I would like to find the time of the last reboot programmatically in Linux. I am using C and C++ in my module.
Is there an API?
On
You could either invoke uptime or take a look at /proc/uptime. Given the current time, and knowing how long the system's been up allows you to calculate the time of the last reboot.
Alternatively, the btime entry in /proc/stat gives the boot time directly (in seconds since the epoch) -- search man proc for btime.
There's no direct api, but you can read
/proc/uptime"file" to learn how many seconds the system have been running, subtract that from the current time - and assume that's when the machine was rebooted.