3

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
  • How accurate does this have to be, using ps you can get it in hours/minutes for the current day, but older processes just say what date they started
    – 123
    Apr 28, 2016 at 14:37
  • @123, I am trying to get some information about a process that pops up only very briefly when I press a button in another program. I want to list programs in ps, top, etc by start time so I can catch it. Apr 28, 2016 at 15:33

2 Answers 2

3

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.

1
1

I am using htop 2.2.0. Please try:

htop --delay=3 --sort-key=STARTTIME

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.