Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Have you already tryed "top" command? – Diogo May 13 '11 at 13:37
@diogo_rocha: how does top help? – Nikratio May 13 '11 at 19:38
up vote 3 down vote accepted

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 24d406a, 2011-08-23.
2 Single devpts instance.

share|improve this answer
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 '11 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.) – grawity May 13 '11 at 14:07
No, its not a virtual server and the maximum number of ptys is 4096. – Nikratio May 13 '11 at 14:24
@Nikratio: I meant the maximum imposed by OpenVZ, not the one set in kernel.pty.max. – grawity May 13 '11 at 15:26
@Nikratio: In your case, though, I can't answer :( Although the given error message doesn't look like one returned by fork()... The program name would be useful to know. – grawity May 13 '11 at 20:03

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

share|improve this answer

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).

share|improve this answer
You mind explaining that a little? – Oliver Salzburg Nov 20 '12 at 22:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.