Wednesday, April 8, 2015

Python to get uptime of Raspberry Pi, in second

In linux, the command "$ cat /proc/uptime" shows how long the system has been on since it was last restarted. ~ http://en.wikipedia.org/wiki/Uptime#Using_uptime


This Python example code get uptime in second, run on Raspberry Pi:
import os

uptime = os.popen("awk '{print $1}' /proc/uptime").readline()
print("uptime(sec) = "+uptime)


No comments: