How to sort ps output by process start time?

Solution 1:

This should work on Linux and SysV5

ps -ef --sort=start_time

Solution 2:

Linux:

$ ps aux --sort=lstart 

OSX:

$ ps aux -O started

Solution 3:

Along with the great answers above, sometimes I just want to see the top 20 offenders by process sorted descending by time, cpu% and memory usage.

For that I use:

ps auxww --sort=lstart | sort -r -k3,4 | head -20

This would be on a CentOS platform, though I've enjoyed the same results on Fedora as well.

Oh and for grins, I sometimes want to remove a set of processes, so I simply use a variant on the above that includes a bit of grep -v action, such as:

ps auxww --sort=lstart | sort -r -k3,4 | grep -v "sbin/httpd" | head -20

Solution 4:

I can't comment yet, but to answer the question about how to reverse the order of a time sort, just put a minus sign (-) in front of the field.
Example: ps -elf --sort=-start_time


Solution 5:

Or try 'ls', as it allows time formats that are easy to sort, and easier to use.

( cd /proc; ls -td --full-time --time-style=+%s [0123456789]*; )

Outputs the date/time in epoch, newest procs at the top.