Friday, May 16, 2014

How to Find Age of a Process

If you need to know how old a process is or how long a process has been running you can find it very easily with ps and stat.  First find the PID of the process you'd like to know how long it's been running. In this example we will use ntp.


  • $ ps -ef |grep ntp
    ntp      62446     1  0  2013 ?        00:01:19 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
Set PID
  • # PID=62446
Then just take the PID and run stat on the PID in the /proc directory
  • # stat /proc/$PID
  • File: `/proc/46448'
  • Size: 0               Blocks: 0          IO Block: 1024   directory
  • Device: 3h/3d   Inode: 48373597    Links: 7


Access: (0555/dr-xr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-02-20 15:28:34.229115802 -0600
Modify: 2014-02-20 15:28:34.229115802 -0600
Change: 2014-02-20 15:28:34.229115802 -0600


  •  Another way to view time of process

    •  ps -eo pid,etime | grep $PID


    No comments:

    Post a Comment