linuxbashprocess

How can I 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?


Solution

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

    ps -eo pid,lstart,cmd
    

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

    Example (from Debian/Jessie command line)

    $ ps -eo pid,lstart,cmd
      PID CMD                                          STARTED
        1 Tue Jun  7 01:29:38 2016 /sbin/init                  
        2 Tue Jun  7 01:29:38 2016 [kthreadd]                  
        3 Tue Jun  7 01:29:38 2016 [ksoftirqd/0]               
        5 Tue Jun  7 01:29:38 2016 [kworker/0:0H]              
        7 Tue Jun  7 01:29:38 2016 [rcu_sched]                 
        8 Tue Jun  7 01:29:38 2016 [rcu_bh]                    
        9 Tue Jun  7 01:29:38 2016 [migration/0]               
       10 Tue Jun  7 01:29:38 2016 [kdevtmpfs]                 
       11 Tue Jun  7 01:29:38 2016 [netns]                     
      277 Tue Jun  7 01:29:38 2016 [writeback]                 
      279 Tue Jun  7 01:29:38 2016 [crypto]                    
          ...
    

    You can read ps's manpage or check Opengroup's page for the other formatters.