Under Linux I can get a process's uptime in seconds with:
echo $(($(cut -d "." -f1 /proc/uptime) - $(($(cut -d " " -f22 /proc/$PID/stat)/100))))
But how can I get it under different OS? ex.: SunOS, HP-UX, AIX?
processuptime
Under Linux I can get a process's uptime in seconds with:
echo $(($(cut -d "." -f1 /proc/uptime) - $(($(cut -d " " -f22 /proc/$PID/stat)/100))))
But how can I get it under different OS? ex.: SunOS, HP-UX, AIX?
Best Answer
On any POSIX-compliant system, you can use the
etime
column ofps
.The output is broken down into days, hours, minutes and seconds with the syntax
[[dd-]hh:]mm:ss
. You can work it back into a number of seconds with simple arithmetic: