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

后端 未结 6 1435
醉梦人生
醉梦人生 2020-12-07 06:49

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 y

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 07:29

    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.

提交回复
热议问题