Simple implementation of uptime instruction

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.