ajwood ajwood - 4 months ago 17
Linux Question

How to get the start time of a long-running Linux process?

Is it possible to get the start time of an old running process? It seems that

ps
will report the date (not the time) if it wasn't started today, and only the year if it wasn't started this year. Is the precision lost forever for old processes?

Answer

You can specify a formatter and use etime, like this command:

ps -eo pid,cmd,etime

The above command will output all processes, with formatters to get PID, command run, and elapsed time.

You can read ps's manpage or check this page for the other formatters: http://pubs.opengroup.org/onlinepubs/000095399/utilities/ps.html

Example:

[birryree@lilun ~]$ ps -eo pid,cmd,etime
  213 [crypto/0]                  52-15:07:00
  214 [crypto/1]                  52-15:07:00
  215 [crypto/2]                  52-15:07:00
  216 [crypto/3]                  52-15:07:00
  ...

My machine's been up for 52+ days, so these processes have been running that long.

Different system, running Fedora:

[root@domU-12-31-39-00-64-B5 ~]# ps -eo pid,cmd,etime
  PID CMD                             ELAPSED
    1 init [4]                    707-20:49:44
    2 [migration/0]               707-20:49:44
    3 [ksoftirqd/0]               707-20:49:44

Machine's been up nearly 2 years, so these processes are the longest running.