The number of used pty's as reported in /proc/sys/kernel/pty/nr is getting constantly larger on my 2.6.32 server.

How can I find out which processes are using the ptys, short of killing them one after another and checking if the usage count decreases?

  • Have you already tryed "top" command?
    – Diogo
    May 13, 2011 at 13:37
  • @diogo_rocha: how does top help?
    – Nikratio
    May 13, 2011 at 19:38

3 Answers 3


This appears to be a bug in Linux kernel1 - the counter is never decremented, even if ptys are deallocated.

In a standard2 setup, ls /dev/pts should show the actual ptys allocated at the moment, and you can run lsof on them to list all processes using a particular pty (or any other file, for that matter).

1 Fixed in Linux 3.2.
2 Single devpts instance.

  • I don't think it's just that. I have programs failing with "fork() failed: out of pty devices". In these cases, there are only a few ptys in /dev/pts, but /proc/sys/kernel/pty/nr is way above /proc/sys/kernel/pty/max.
    – Nikratio
    May 13, 2011 at 13:56
  • @Nikratio: Is it an openvz-based server? Sometimes they have crazy limits; check /proc/user_beancounters. (I've had to deal with a VPS host which had 4 pty limit by default.) May 13, 2011 at 14:07
  • No, its not a virtual server and the maximum number of ptys is 4096.
    – Nikratio
    May 13, 2011 at 14:24
  • @Nikratio: I meant the maximum imposed by OpenVZ, not the one set in kernel.pty.max. May 13, 2011 at 15:26

Try using fuser or lsof to see which process is using them.


This shows what you want:

find /proc -maxdepth 1 -type d -name "[0-9]*" | while read f; do echo $(cat "$f/cmdline") " ${f:6} " $(readlink "$f/fd/0"); done

ok, to break this thing down: - find all directories that contain only numbers in proc - just in proc, no subdirectories. by convention, these are only process ids. - while read reads each line and stores in a shell variable (if this were a script, i'd've called it procpiddir or something cool like that - it's cli so i call it something short). - the cmdline file tells you what was run to make that pid (not exactly, but we'll go with that) - ${f:6} is bash variable manipulation - basically discard the first 6 characters in the name - '/proc/' in this case - readlink follows a link to its conclusion. since fd0 is stdin (fd1 is stdout, fd2 is stderr) it only makes sense that this would lead you to the tty the process is running under.

there's no good reason to be quoting this stuff - there's no way any of these variables would have spaces or other funny characters. it's just habit. oh, and $(cmd) makes it look like the output of a command is a shell variable (maybe someone better with bash should explain this better or find supporting links - this is afaik).

  • 2
    You mind explaining that a little? Nov 20, 2012 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .