Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

How can I get the process with the biggest pid using ps?

share|improve this question

This doesn't use ps, but parsing ps is likely to be difficult (not to mention non-portable). This ought to be easier (and at least a bit more portable):

( cd /proc; printf "%s\n" *; ) | sort -n | tail -n 1

That looks for the highest numbered directory inside /proc, which works because on many Unix systems there's one /proc/### directory per pid that contains information about that process.

share|improve this answer
ps -eo pid= | sort -rn | head -n 1

would be POSIX.

On Linux, process ids share the same namespace as the thread ids. There, you can do:

ps -Leo tid= | sort -rn | head -n 1

To get the highest thread or process id number.

share|improve this answer
Forgot about -o - that definitely makes it easier to parse ps than I was thinking. But you missed -e, since I'm assuming the OP wants all processes on the machine. – godlygeek Jul 1 '14 at 16:27
@godlygeek, yes I did add the -e while you were writing your comment. – Stéphane Chazelas Jul 1 '14 at 16:31
ps [whatever options you like] $(cd /proc; ls -d [0-9]* | sort -n | tail -1)
share|improve this answer

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.