I want to run top is batch / non-interactive mode with -b
. However I want the output sorted by PID. What command line option does this? I'm using Debian Lenny and the -o pid
option from here ( http://www.unixtop.org/man.shtml ) doesn't work.
Linux – Debian – top(1) in batch mode, but sorted by PID
debianlinuxmonitoringtop
Best Answer
For me, on an Ubuntu system, with no
~/.toprc
or/etc/toprc
runningtop
3.2.8, The primary sort is%CPU
and the secondary sort isPID
.To set up
top
to sort byPID
for batch mode:If you don't have a
~/.toprc
to begin with:top
in interactive mode.W
. That will write a new~/.toprc
with the current settings.top
(pressq
).To create the necessary configuration files:
~/.toprc
file. You will need this for a later step. Let's call this file~/.toprc.ORIG
(you can choose another name if you prefer).top
in interactive mode.F
, thena
, then Enter. That will selectPID
as the sort field.R
. That will reverse the sort so it's ascending.W
. That will write a new~/.toprc
with the current settings.top
(pressq
).mv ~/.toprc ~/toprc.PIDSORT
(or choose a name you prefer)cp ~/.toprc.ORIG ~/.toprc
).To use the file you created to output
top -b -n1
sorted byPID
, create a script like this: