What API do I call to get the system uptime?

The system call you’re looking for is sysinfo(). It’s defined in sys/sysinfo.h Its signature is: int sysinfo(struct sysinfo *info) Since kernel 2.4, the structure has looked like this: struct sysinfo { long uptime; /* Seconds since boot */ unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ unsigned long totalram; /* Total … Read more

Retrieve system uptime using C#

public TimeSpan UpTime { get { using (var uptime = new PerformanceCounter(“System”, “System Up Time”)) { uptime.NextValue(); //Call this an extra time before reading its value return TimeSpan.FromSeconds(uptime.NextValue()); } } }