2

Is there any way to get the PID of the top CPU/MEM usage, I need to use that in a script, top command doesn't seem to work for it.

2 Answers 2

3

ps has many options for displaying and sorting details about processes.

e.g. ps hax o pid k -time | head -n 1 will give you the PID of the process with the most CPU time used.

See the man page for full details. The man page functions well enough as a reference but is not a tutorial - IMO your best option is to read and experiment until you understand what it can do and how to use it best. AFAIK, there is no tutorial-style documenation for ps available anywhere.

2

Try something like this:

top -b -n1 | tail -n+8 | sort -nr -k9
0

You must log in to answer this question.

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