Sorting by socket usage

So, I’ve got hosting by the overly-restrictive people, and one of the problems I have is that I’m constantly running out of Unix sockets (running out of inodes is the other problem: medium-volume Maildir + limited inode ext2 filesystem = problems). The limit is a ridiculously low 360 sockets. Running Postfix, with all those sub processes that communicate with each other, I’ve had to cut the maximum number of processes down from the default of 100 to 15, which is still hitting problems under periods of high load.

Anyway, I thought this command would be handy to share. It lists all of the processes on your system using Unix sockets, and counts how many there are for each process.

lsof -U | awk '$0=$1' | sort | uniq -c | sort -k1n

Here’s the top 15 on my machine:

[root@themachine ~]# lsof -U | awk '$0=$1' | sort | uniq -c | sort -k1n | tail -n15
      2 qmgr
      4 dovecot
      5 proxymap
      5 verify
      8 perl
      8 spawn
     11 dovecot-a
     13 tlsmgr
     15 mysqld
     16 trivial-r
     18 anvil
     18 imap
     23 imap-logi
     74 smtpd
     76 master

Note that dovecot (the green ones) and MySQL take up several, but most are taken up by Postfix and friends (the blue ones).  Sigh.  This is really a good architecture, but just not something is set up to handle on their VPS plans.  I guess that’s a fair tradeoff for unlimited bandwidth, but it sure is inconvenient.