CPU usage in Linux under explanation

Source: Internet
Author: User
Tags cpu usage

CPU usage is actually the CPU resource that your program runs on, indicating that your machine is running a program at some point in time. Higher usage means that your machine runs a lot of programs at this time, whereas less

The top command is a common system performance analysis tool under Linux that allows you to view the resource usage of each process in real time.

Top-10:02:17 up (19:18), 4 users, load average:2.11, 2.32, 2.14tasks:251 Total, 1 running, 247 sleeping,    3 stopped, 0 zombiecpu (s): 0.5%us, 0.8%sy, 0.4%ni, 98.1%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%stmem:23591m Total,  23181M used, 409M free, 861M buffersswap:12288m total, 1026M used, 11262M free, 16459M cached                                                                                                                      PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND 39494 i2kuser 0 15.5g 2.7g 12m S 6 11.8 124                                                                                                                          5:06 Java                                                                                                                          37462 i2kuser 0 1906m 753m 11m S 3 3.2 558:53.85 Java      20073 Root 17-3 423m 154m 16m S 2 0.7 480:39.09 Pmu.bin                                                                                                                        14                                                                                                                 Sat Root 12528 2036 592 S 1 0.0 6:06.54 get_os_statisti 855 Root 0 0 0 S 0 0.0 65:0                                                                                                                        7.89 Kipmi0                                                                                                                           21846 Root 0 9072 1288 856 R 0 0.0 0:00.17 Top      32669 Oracle 0 11.8g 27m 24m S                                                                                                                        0 0.1 3:47.58 Oracle                                                        32679 Oracle 0 11.7g 62m 60m S 0 0.3 16:04.39 Oracle                                                                    1 Root 0 10560 872 736 S 0 0.0 0:1                                                                                                                              1.27 Init       2 Root 0 0 0 0 S 0 0.0 0:00.18 Kthreadd

View CPU line, CPU (s): 0.5%us, 0.8%sy, 0.4%ni, 98.1%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st

The explanation on Google is:

Us:is meaning of "user CPU time" sy:is meaning of "system CPU time" ni:is meaning of "nice CPU time" id:is meaning of "id Le "wa:is Meaning of" iowait "hi:is meaning of" hardware IRQ "(servicing hardware interrupts) si:is meaning of" software I RQ "(servicing software interrupts) St:is meaning of" Steal Time "(time in involuntary wait by virtual CPUs while Hypervis Or is servicing another processor)

The Chinese explanation is:

Percentage of CPU occupied by%us user space, percentage of CPU consumed by%sy kernel space, percentage of CPU that has changed priority in user process space, and%id Idle CPU percentage, which reflects the busy level of a system CPU. The larger the more idle; the percentage of CPU%wa waiting for input and output (I/O),%hi refers to the time the CPU handles hardware interrupts,%si value is the time the CPU handles software outages,%st when Hypervisor services another virtual processor, the virtual CPU waits for the actual CPU The percentage of time

CPU usage can be derived directly from the top command

In the kernel of Linux, there is a global variable: Jiffies. Jiffies represents time. Its units vary depending on the hardware platform. A constant Hz is defined in the system, representing the number of minimum time intervals per second. So the jiffies unit is 1/hz. The Intel platform Jiffies Unit is 1/100 seconds, which is the minimum time interval the system can distinguish. Each CPU time slice, jiffies must add 1. The CPU utilization is expressed by dividing the jiffies of the execution user state + the system state by the total jifffies.

In the Linux system, the CPU utilization is calculated from the/proc/stat file, the first few lines of this file record the user state of each CPU, System state, idle state of the different jiffies, common monitoring software is the use of/proc/ This data in stat calculates the CPU utilization.

Contains information about all CPU activity, and all values in the file are accumulated from the start of the system to the current moment.
i2000:~ # cat/proc/statcpu 11772990 3685567 11586702 994389437 1502196 0 617801 0 0 0cpu0 1925911 145536 1479330 1233775 944584 0 71441 0 0 0cpu1 1493902 723778 1332508 123809933 398061 0 186171 0 0 0cpu2 1218152 138174 1327108 125164685 28 448 0 67759 0 0 0cpu3 1408917 788649 1408734 124241479 31922 0 64644 0 0 0cpu4 1347669 144848 1477635 124881583 38168 0 54 423 0 0 0cpu5 1318674 827204 1696224 124014206 24080 0 63939 0 0 0cpu6 2189237 147904 1743240 123789739 16803 0 57403 0 0 0cpu7 870526 769470 1121920 125110268 20126 0 52016 0 0 0intr 6041226474 39 9 0 2 31344 0 2 0 356 0 0 29 130 0 879833 0 0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 110214 0 94382684 987 0 83207017 751 0 120017596 99 0 23038227 0 1319554 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ctxt 11176275226btime 1440513807process Es 83672461procs_running 1procs_blocked 0softirq 5289823244 0 2558726670 741 402209688 239962 0 3821129 628773714 0 169605 1340

Parameter interpretation
User (432661) accumulates from the start of the system to the current time, the CPU time (in jiffies), which does not include the nice value as a negative process. 1jiffies=0.01 sec
Nice (13295) accumulate from the start of the system to the current moment, the CPU time occupied by a process with a negative Nice value (unit: jiffies)
System (86656) accumulates at the current moment from the start of the boot, Core time (unit: jiffies)
Idle (422145968) accumulate from the start of the system to the current time, in addition to the hard disk IO wait time other than the Wait time (unit: jiffies)
Iowait (171474) accumulated from the start of the system to the current time, hard disk IO wait time (in jiffies),
IRQ (233) accumulates from the start of the system to the current moment, hard Interrupt time (unit: jiffies)
SOFTIRQ (5346) accumulated from the start of the system to the current moment, soft interrupt time (unit: jiffies)

CPU Time =USER+SYSTEM+NICE+IDLE+IOWAIT+IRQ+SOFTIRQ

The "Intr" line gives the interrupt information, the first is the number of interrupts that have occurred since the system started, and then each number corresponds to the number of times that a particular interrupt has occurred since the system started.
"Ctxt" gives the number of context exchanges that have occurred since the system started.
"Btime" gives the time, in seconds, from the start of the system to the present.
Processes (Total_forks) The number of tasks created since the system started.
"Procs_running": the number of tasks currently running the queue.
"Procs_blocked": the number of tasks that are currently blocked.

Then the CPU utilization calculation method: can use to take two sampling points, calculate its difference value. (idle2-idle1) The/CPU2-CPU1 shell script is as follows:
#!/bin/bashcpu_1=$ (sed-n ' 1p '/proc/stat | awk ' {print $ "" $ "" $4 "" $ $ "" $6 "" $7 "" $8} ') ide_1=$ (echo $CPU _1 | awk ' {print $4} ') total_1=$ (echo $CPU _1 | awk ' {print $1+$2+$3+$4+$5+$6+$7} ') echo "#################################### # # # "echo" Sleep 5 sec begin ... "Sleep 5echo" Sleep 5 sec End ... "cpu_2=$ (sed-n ' 1p '/proc/stat | awk ' {print $ ' "$ $" "$4" "$ $" "$6" "$7" "$8} ') ide_2=$ (echo $CPU _2 | awk ' {print $4} ') total_2=$ (echo $CPU _2 | awk ' {print $1+$2+$3+$4+$5+$6+$7} ') ide= ' expr $IDE _2-$IDE _1 ' total= ' expr $Total _ 2-$Total _1 ' tem_rate= ' expr 1-$IDE/$Total | Bc-l ' rate= ' expr $tem _rate*100 | Bc-l ' display_rate= ' expr ' scale=3; $rate/1 "|BC ' #displayecho" The CPU useage rate was: $display _rate% "echo" "echo" now use TOP command to Caculate. "  rate_top=$ (top-n 1 | grep "Cpu" | awk ' {print $} ' | cut-d "%"-F 1) display_rate_top= ' expr 100.000-$rate _top|bc-l ' echo "The CPU useage rate is: $display _rate_top%" echo "########################################" Exit 0

  

CPU usage in Linux under explanation

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.