2015-09-24
Simple implementation of uptime instruction
Report the current time, how long the system has been running, the number of users currently logged in, the average load for the last 1 minutes, 5 minutes, and 15 minutes.
1. Current system time
Get by Time (NULL)
2. System running time, recorded in the/proc/uptime file inside
The 1th value is the system boot to the current time, the 2nd value is the System idle time
3. The number of users currently logged in, recorded in the utmp log file
Count the number of ut_type==user_process records, that is, the current number of users by reading the utmp file
4. The average load of the last 1 minutes, 5 minutes, 15 minutes, recorded in the/proc/loadavg file
The first 3 values, namely the last 1 minutes, 5 minutes, 15 minutes of average load;
The 4th value is the proportion of the number of processes that are running and the total number of processes
The 5th number is the process number of the most recent running process
5. Based on the above knowledge, the results of the uptime operation are as follows:
6. Source code
http://download.csdn.net/detail/qq123386926/9137083