How to find uptime of a linux process
Solution 1:
As "uptime" has several meanings, here is a useful command.
ps -eo pid,comm,lstart,etime,time,args
This command lists all processes with several different time-related columns. It has the following columns:
PID COMMAND STARTED ELAPSED TIME COMMAND
PID
= Process ID
first COMMAND
= only the command name without options and without argumentsSTARTED
= the absolute time the process was startedELAPSED
= elapsed time since the process was started (wall clock time), format [[dd-]hh:]mm:ss
TIME
= cumulative CPU time, "[dd-]hh:mm:ss" format
second COMMAND
= again the command, this time with all its provided options and arguments
Solution 2:
If you have a limited version of ps
such as is found in busybox
, you can get the process start time by looking at the timestamp of /proc/<PID>
. For example, if the pid you want to look at is 55...
# ls -al /proc | grep 55
dr-xr-xr-x 7 root root 0 May 21 05:53 55
... and then compare it with the current date...
# date
Thu May 22 03:00:47 EDT 2014
Solution 3:
I think you can just run:
$ stat /proc/1234
1234 being the process id.
example with two processes started at the same hour minute seconds but not the same milliseconds:
$ stat /proc/9355
...
Access: 2017-11-13 17:46:39.778791165 +0100
Modify: 2017-11-13 17:46:39.778791165 +0100
Change: 2017-11-13 17:46:39.778791165 +0100
$ stat /proc/9209
...
Access: 2017-11-13 17:46:39.621790420 +0100
Modify: 2017-11-13 17:46:39.621790420 +0100
Change: 2017-11-13 17:46:39.621790420 +0100