Show top running processes by the number of open filehandles they have

lsof | awk '{print $1}' | sort | uniq -c | sort -rn | head
I think I could cut down the number of pipes here, any suggestions?
Sample Output
sten@fenris:~$ sudo lsof | awk '{print $1}' | sort | uniq -c | sort -rn | head
   3002 php5-cgi
    122 master
    116 sshd
    115 freeswitc
     82 mysqld
     60 ssh
     60 slapd
     52 lighttpd
     47 beam.smp
     43 inet_geth

4
By: sud0er
2009-02-19 19:45:09

These Might Interest You

  • When dealing with system resource limits like max number of processes and open files per user, it can be hard to tell exactly what's happening. The /etc/security/limits.conf file defines the ceiling for the values, but not what they currently are, while ulimit -a will show you the current values for your shell, and you can set them for new logins in /etc/profile and/or ~/.bashrc with a command like: ulimit -S -n 100000 >/dev/null 2>&1 But with the variability in when those files get read (login vs any shell startup, interactive vs non-interactive) it can be difficult to know for sure what values apply to processes that are currently running, like database or app servers. Just find the PID via "ps aux | grep programname", then look at that PID's "limits" file in /proc. Then you'll know for sure what actually applies to that process. Show Sample Output


    11
    cat /proc/PID/limits
    dmmst19 · 2011-12-14 16:49:06 0
  • 'ps ax' provides the fill list of running processes. 'grep -c [c]at' will find all processes that match 'cat' without matching itself.... Show Sample Output


    3
    ps ax | grep -c [c]at
    utoxin · 2010-09-23 20:18:29 0
  • This is different that `who` in that who only cares about logged-in users running shells, this command will show all daemon users and what not; also users logged in remotely via SSH but are running SFTP/SCP only and not a shell. Show Sample Output


    1
    ps aux | sed -n '/USER/!s/\([^ ]\) .*/\1/p' | sort -u
    infinull · 2010-02-10 05:56:26 2
  • If you have ever been trying to look for a list of processes based on their elapsed time you don't need to look any further. This command lets you find the list of processes ordered in a reversed order (oldest at the top) that have been running for over an hour on your system. Any system processes are filtered out, leaving only user initiated ones in. I find it extremely useful for debugging and performance analysis. Show Sample Output


    0
    ps -eo etime,pid,pcpu,ppid,args | sed -e '/\[.\+\]/d' -e '/^[ \t]*[0-9]\{2\}:[0-9]\{2\} /d' | sort -k1r
    neurodrone · 2014-02-14 00:22:31 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: