sorting ps output by CPU time on linux

I want to sort ps output by process CPU time (“TIME” column).
I’ve tried:

ps -aux --sort cputime | tail

but it doesn’t sort by cpu time.
I’m running with:

ps --version 
procps version 3.2.7

and kernel: 2.6.18

Asked By: Avner Levy

||

I think that is not cputime but time that u want 🙂

ps -aux --sort -time

Just post after --sort the exact name of the column that you want.

with tail:

ps -aux --sort +time | tail

+- for selecting order

Answered By: NIZ

This sorts by CPU:

ps aux --sort -pcpu

This is how it’s done!

Answered By: Edwin Hermann

The questioner wanted to sort by the "TIME" column (displayed when you run ps -aux), which is how I ended up here, wanting the same thing. This column contains the TOTAL CPU execution time (on Ubuntus anyway, your linux may vary).

Neither of the 2 answers worked for me. But a combination of those answers with the original question led to the correct command. The questioner just needed to add a dash in front of the cputime flag:

ps -aux --sort -cputime

This displays a list of processes, sorted in descending order by total cpu execution time since last reboot.

Answered By: Morgan Leininger
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.