Is there a way to view processes by the time they were started? top
and htop
have an option for sorting by how much time a process has been running, but I would like to sort by when the process began (most recent on top).
2 Answers
You can use something like this
while sleep 1;do ps -eo start_time,pid,euser,args:100 --sort start_time;done
This will list all processes running in order of start time although it will be latest at the bottom. The loop update every second, if you need a finer time period change the sleep as needed.
If you want the latest at the top you can pipe into tac
while sleep 1;do ps -eo start_time,pid,euser,args:100 --sort start_time | tac ;done
This will reverse the order.
From the comment above though i don't think listing in order of start time is what you really want.If you know the name of the process beforehand then you can use
while sleep 0.1;do ps -eo start_time,pid,euser,args:100 | grep YOURCOMMAND;done
To just check for that single commands start time and output nothing if it is not running.
-
Alternatively, you can use the
watch
command for looping. linfo.org/watch.html– AldeeFeb 21, 2018 at 8:20
ps
,top
, etc by start time so I can catch it.