0

This question already has an answer here:

I need to get the number of seconds since the last reboot, using ksh.

What is the command or function to achieve this?

marked as duplicate by Jeff Schaller, dr01, Archemar, don_crissti, vonbrand Mar 17 '16 at 18:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

For Ubuntu, Redhat, Suse, we can have this file. Not much sure about AIX, though

See the output of:

cat /proc/uptime

If this is not available on AIX, then try to execute command uptime

  • its not working on AIX 7. $ oslevel 7.1.0.0 $ cat /proc/uptime cat: cannot open /proc/uptime – Venkat Teki Mar 17 '16 at 10:34
1

If you check the psinfo for process with PID 1 from /proc directory you can get this structure:

struct   pr_timestruc64_t pr_start; /* process start time, time since epoch */

Here is the webpage you can use for reference.

0

This answer is blatantly copied from Gilles' answer at How to get a process uptime under different OS?:

t=$(LC_ALL=POSIX ps -o etime= -p 1)
d=0 h=0
case $t in *-*) d=$((0 + ${t%%-*})); t=${t#*-};; esac
case $t in *:*:*) h=$((0 + ${t%%:*})); t=${t#*:};; esac
s=$((10#$d*86400 + 10#$h*3600 + 10#${t%%:*}*60 + 10#${t#*:}))

This leaves you with the number of seconds of uptime in $s.

We're making the assumption that init's start time is when we start counting "uptime" and also that init is PID 1 (true in my limited testing).

Not the answer you're looking for? Browse other questions tagged or ask your own question.