Linux commands: Difference between revisions

Jump to navigation Jump to search
5,439 bytes added ,  5 October 2023
Line 303: Line 303:


=== System CPU usage ===
=== System CPU usage ===
CPU usage / system load average
==== Using WQL query ====
* {{Win}}:  
on {{Win}}:  
** namespace: ROOT\CIMV2
* namespace: ROOT\CIMV2
** WQL query: {{kbd | key= SELECT LoadPercentage FROM Win32_Processor}}; No need to divid by CPU cores number for Win8
* WQL query: {{kbd | key= SELECT LoadPercentage FROM Win32_Processor}}; No need to divide by CPU cores number for Win8
** output example: 24 ([https://msdn.microsoft.com/zh-tw/library/system.uint16(v=vs.110).aspx UInt16, 16 bit Unsigned Integer]) unit: %
* output example: 24 ([https://msdn.microsoft.com/zh-tw/library/system.uint16(v=vs.110).aspx UInt16, 16 bit Unsigned Integer]) unit: %
** CPU usage = LoadPercentage; unit: %
* CPU usage = LoadPercentage; unit: %
* freebsd, {{Linux}} & {{Mac}}:  
 
** PHP function [http://php.net/manual/en/function.sys-getloadavg.php sys_getloadavg()] unit: %; '''Need''' to divid by CPU cores number
==== Using PHP function ====
on freebsd, {{Linux}} & {{Mac}}:  
* PHP function [http://php.net/manual/en/function.sys-getloadavg.php sys_getloadavg()] unit: %; '''Need''' to divide by CPU cores number
 
==== Using mpstat command ====
Example result of {{kbd | key=<nowiki>mpstat 2 2 | grep -E '^Average'</nowiki>}} on {{Linux}}
<pre>
Average:    all    1.31    0.00    0.25    0.00    0.00    0.00    0.00    0.00    0.00  98.43
</pre>
 
The output of the mpstat command includes an "Average" line, which provides detailed information about CPU usage, similar to the %Cpu(s) line in the top command but with a slightly different format. Here's an explanation of the columns in the "Average" line:
 
* all: This represents the average values for all CPU cores.
The subsequent columns represent percentages of CPU usage:
* The first column (1.31) is the CPU usage by user-space processes, indicating the percentage of time the CPU is occupied by user programs and processes.
* The second column (0.00) is the CPU usage by system kernel processes, indicating the percentage of time the CPU is occupied by the operating system kernel.
* The third column (0.25) is the CPU usage by processes with a "nice" priority, representing the percentage of CPU time used by processes adjusted with the nice command.
* The fourth column (0.00) is the CPU's idle time, indicating the percentage of time the CPU is not executing any tasks.
* The fifth column (0.00) is the CPU's time spent waiting for I/O operations to complete, indicating the percentage of time the CPU is waiting for disk or other I/O device responses.
* Columns six through eleven (0.00 to 0.00) represent CPU usage in other states, such as the time spent handling hardware or software interrupts and time spent in virtualized environments with CPU steal time.
* The last column (98.43) indicates the percentage of time the CPU is idle, representing the time when the CPU is not executing any tasks.
 
In the above example, the CPU usage is as follows:
 
* User processes have used 1.31% of CPU time.
* System kernel processes have used 0.00% of CPU time.
* There are no "nice" priority processes using CPU time.
* The CPU is idle for 98.43% of the time.
* There is no time spent waiting for I/O operations to complete.
* There is no time spent handling hardware or software interrupts.
* There is no CPU steal time in a virtualized environment.
 
==== Using top command ====
 
# Command: Using top command e.g. {{kbd | key=<nowiki>top</nowiki>}}  on {{Linux}} or {{Mac}}
# Command: Using top command e.g. {{kbd | key=<nowiki>top -l 2 | grep -E '^CPU'</nowiki>}} on {{Mac}}
# Command: Using top command e.g. {{kbd | key=<nowiki>top -n 1 | grep '%Cpu(s)'</nowiki>}} on {{Linux}}
 
Example result of {{kbd | key=<nowiki>top -n 1 | grep '%Cpu(s)'</nowiki>}}
<pre>
%Cpu(s):  1.5 us,  1.5 sy,  0.0 ni, 96.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
</pre>
 
The result provided is the information about CPU usage obtained through the `top` command. It shows the percentages of different CPU states, and each column is explained as follows:
 
* `%Cpu(s)`: This is the header indicating that the following numbers are percentages related to CPU usage.
 
* `us` (User): It represents the CPU usage by user-space processes, which includes the percentage of time the CPU is occupied by user programs and processes. In this case, it's 1.5%, indicating that 1.5% of CPU time is used for running user programs.
 
* `sy` (System): It represents the CPU usage by system kernel processes, indicating the percentage of time the CPU is occupied by the operating system kernel. In this case, it's 1.5%, indicating that 1.5% of CPU time is used for handling operating system kernel tasks.
 
* `ni` (Nice): It represents the CPU usage by processes with a "nice" priority, which includes the percentage of CPU time used by processes adjusted with the `nice` command. In this case, it's 0%, indicating that there are no "nice" processes running.
 
* `id` (Idle): It represents the percentage of time the CPU is in an idle state, indicating the percentage of time the CPU is not executing any tasks. In this case, it's 96.9%, meaning that 96.9% of CPU time is idle.
 
* `wa` (IO Wait): It represents the CPU usage while waiting for I/O operations to complete, indicating the percentage of time the CPU is waiting for disk or other I/O device responses. In this case, it's 0%, indicating that the CPU is not waiting for I/O to complete.
 
* `hi` (Hardware IRQ): It represents the CPU usage caused by hardware interrupts, indicating the percentage of time spent handling hardware device interrupts. In this case, it's 0%, indicating that the CPU is not handling hardware interrupts.
 
* `si` (Software IRQ): It represents the CPU usage caused by software interrupts, indicating the percentage of time spent handling software interrupts. In this case, it's 0%, indicating that the CPU is not handling software interrupts.
 
* `st` (Steal Time): It represents the "steal time" in a virtualized environment, indicating the percentage of time a virtual machine's CPU is taken away when sharing host CPU resources with other virtual machines. In this case, it's 0%, meaning there is no virtualization steal time.
 
In summary, this output indicates the following CPU usage:
 
* User programs are using 1.5% of CPU time.
* System kernel tasks are using 1.5% of CPU time.
* There are no "nice" processes running.
* 96.9% of CPU time is idle.
* There is no time spent waiting for I/O operations to complete.
* There is no time spent handling hardware or software interrupts.
* There is no virtualization steal time.


=== System memory usage ===
=== System memory usage ===
Anonymous user

Navigation menu