Search This Blog


Start time of a Linux PID

date --date="`ps -p -o lstart= `" +%s

Example where 683 is the PID:

# Only print the start time in ctime format so we can convert it using the date command
ps -p 683 -o lstart=
Wed Apr 16 18:46:32 2014
# pipe the result into the date command to convert to epoch time
date --date="`ps -p 683 -o lstart= `" +%s
# Convert from epoch time back to regular time to confirm we’ve done it right
date -d @1397688392
Wed Apr 16 18:46:32 EDT 2014

Alternatively you could do some realllyyy crazy stuff in /proc//stat but I would highly recommend not :P

STARTTIME=$(awk '{print int($22 / 100)}' /proc/$PID/stat)
UPTIME=$(awk '{print int($1)}' /proc/uptime)
NOW=$(date +%s)
date -d @$DIFF

Crazy stuff with /proc explanation:

No comments:

Post a Comment