New answers tagged

7

On a standard UNIX system (based on the original sources *), uptime reads /var/adm/utmpx and checks for the last time of reboot entry. In other words: this is retrieving the date you also get with who -b and then computes the time since then. *) uptime is a link to the w program and was introduced by BSD around 1980.


71

On my system it gets the uptime from /proc/uptime: $ strace -eopen uptime open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 open("/lib/libproc-3.2.8.so", O_RDONLY|O_CLOEXEC) = 3 open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 open("/proc/version", O_RDONLY) = 3 open("/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 3 ...


10

As long as I know, uptime uses /proc/uptime to calculate system uptime. You can see it more clearly in the source code uptime.c FILE *fp; fp = fopen ("/proc/uptime", "r"); if (fp != NULL) { char buf[BUFSIZ]; char *b = fgets (buf, BUFSIZ, fp); if (b == buf) { char *end_ptr; double upsecs = c_strtod ...



Top 50 recent answers are included