uptime in unix

marcus at deepfort.com marcus at deepfort.com
Sun Sep 19 23:36:54 CEST 2004


Oli Schwarz wrote:

>Hello,
>
>how can I read out the uptime of a unix system in python (Linux and *BSD).
>
>I have not found a uptime-function in the Library.
>
>Regards 
>Oli
>
You can pull the uptime in seconds from /proc/uptime in Linux (use 
uptime in BSD, prob. Darwin).
How you retrieve it is a matter of personal taste..


For instance:

import commands
#linux
commands.getoutput('cat /proc/uptime')
etc..


Obviously if you're going to use popen, you could use the unix uptime 
command anyway I guess.

I'm guessing that's not what you want though, since it's just using a 
shell..



More information about the Python-list mailing list