uptime in unix

Heiko Wundram heikowu at ceosg.de
Mon Sep 20 10:18:18 CEST 2004

Am Sonntag, 19. September 2004 23:21 schrieb Oli Schwarz:
> Are these things handled like in Java? Doesn't Python know anything
> about such platform specific things?

Python knows a lot about platform specific things (look at five different 
implementations of os.path), or different implementations of mmap, which 
works completely different on Unix than on Windows.

But, Python abstracts those differences away, and presents a coherent 
interface to all this functionality. There are only very few function which 
are actually platform specific.

Uptime and the like (for example, list of loaded kernel modules is another 
candidate) is something that's not only platform specific, but also very 
operating-system specific. Take Linux: it "invented" the /proc filesystem 
(well, actually not the filesystem, but the hierarchy as it is know) to 
present this kind of system info from the kernel, so open file, read, close 
file. Take *BSD: they have /proc, but it's only present when running in Linux 
compatability mode. Standard BSD has a SYSCALL to retrieve uptime using some 
form of kernel config management with read only keys. Take Solaris: uptime is 
retrieved using a SYSCALL, but this is a specific SYSCALL rather than some 
config subsystem syscall as with BSD.

And Windows? "What's Uptime?" :-)

So, I guess uptime is just a concept that's so wildly different among 
different operating systems (although the platform may be the same, for *nix 
it's Posix, pretty much) that it's simply better not to add something like 
this to the std-lib (I guess Pythonistas once reasoned like this, and I can 
agree fully), but rather let the programmer do the job.

And, oh, if you thought that parsing the output of /usr/bin/uptime would solve 
your problems: no, it only creates more, because the output of this command 
isn't standardized either. With Linux you get the GNU version (well most of 
the time, but not necessarily either), whose output is slightly different 
than what the Posix standard specifies, whose output is slightly different 
than the *BSD versions (who have a longer history and remain backwards 
compatible), whose output is slightly different to the SysV version of uptime 
(which needed to be different to *BSD in the 80s to bind users, so it was 
made different), whose output... You name it... :-)


More information about the Python-list mailing list