I want to sort the output of the following command based on pcpu
:
ps -p 29492 -L -o pid,tid,psr,pcpu
I tried the following:
ps -p 29492 -L -o pid,tid,psr,pcpu --sort=pcpu
But it doesn't seem to work. How can I fix this?
linuxpssort
I want to sort the output of the following command based on pcpu
:
ps -p 29492 -L -o pid,tid,psr,pcpu
I tried the following:
ps -p 29492 -L -o pid,tid,psr,pcpu --sort=pcpu
But it doesn't seem to work. How can I fix this?
Best Answer
It's likely that in your implementation of
ps
, sorting only applies to processes, not threads (seefancy_spew()
inprocps
'display.c
). As far as I can tell, if you want to sort threads you need to post-process the output; e.g.but then the header line gets mixed up in the output. If you want to keep the header line, you can pull it out and print it separately:
You can also simply drop the header line by specifying blank header values for all the output selectors:
In all these cases, you can reverse the sort by adding
-r
to thesort
parameters. The sort order may be affected byLC_NUMERIC
orLC_ALL
; settingLC_ALL=C
will sort values with a decimal point.
correctly.