Skip to content

Instantly share code, notes, and snippets.

@ahmed-musallam
Created January 2, 2018 18:44
Show Gist options
  • Save ahmed-musallam/013cc1f20e942f6e9fe196a131059faa to your computer and use it in GitHub Desktop.
Save ahmed-musallam/013cc1f20e942f6e9fe196a131059faa to your computer and use it in GitHub Desktop.
See how many files each pid is opening in macOs
# based on https://www.reddit.com/r/osx/comments/3ewn93/too_many_open_files_in_system_what_is_causing_this/ctj765h/
# will print a list of comma seperated enties, each entry is in this format: <PID name>, <PID>, <Files open>
sudo lsof -n | perl -pe '$x = <>; while(<>) { ($cmd, $pid, $rest) = split(/\s+/); $cmds{$pid} = $cmd; $pids{$pid}++;} while( ($key, $val) = each %pids) { $pidName=$cmds{$key}; printf "$pidName,$key,$val \n" } ;'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment