You can use the sys/proctable
gem to get the system boot time and calculate the uptime in minutes. Here's how you can do it:
main.rb186 chars7 lines
In this code, we first require the sys/proctable
gem which provides a way to get information about system processes. We then use the ps
method to get information about the process with pid
1 which is always the init
process and has been running since the system was booted.
We retrieve the start_time
of the init
process as a Time
object and calculate the difference between the current time and the boot time in minutes. Finally, we print the uptime in minutes with two digits after the decimal point using the round
method.
gistlibby LogSnag