We can view the native performance of various processes in an OS by using the following tools:
To view a dynamic real-time view of the running processes in an OS, use the following command:
$ top
Output:top - 15:52:40 up 275 days, 1:27, 2 users, load average: 5.33, 4.59, 4.53
Tasks: 353 total, 10 running, 342 sleeping, 1 stopped, 0 zombie
%Cpu(s): 32.5 us, 25.0 sy, 0.0 ni, 41.8 id, 0.0 wa, 0.0 hi, 0.6 si, 0.0 st
KiB Mem : 24688724 total, 2805744 free, 1733244 used, 20149736 buff/cache
KiB Swap: 34552824 total, 34061312 free, 491512 used. 20726872 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1631 www-data 20 0 434648 88640 25600 R 69.2 0.4 0:02.09 php
1642 www-data 20 0 431700 84768 25708 R 59.6 0.3 0:01.80 php
1389 www-data 20 0 4945088 204120 102236 S 52.6 0.8 0:13.24 apache2
1647 www-data 20 0 408076 59836 25592 R 33.1 0.2 0:01.00 php
1651 www-data 20 0 410308 62120 25748 R 32.1 0.3 0:00.97 php
1633 www-data 20 0 398944 51540 25400 S 24.8 0.2 0:00.75 php
1655 www-data 20 0 405964 58124 25348 R 22.5 0.2 0:00.68 php
1644 www-data 20 0 396896 50316 25700 S 22.2 0.2 0:00.67 php
1649 www-data 20 0 396896 50088 25472 S 21.2 0.2 0:00.64 php
612 www-data 20 0 4895016 234944 183188 R 20.5 1.0 0:09.28 apache2
1085 www-data 20 0 4812596 142684 96404 S 19.9 0.6 0:03.93 apache2
1653 www-data 20 0 396896 50216 25600 S 18.9 0.2 0:00.57 php
1350 www-data 20 0 4815848 137208 88508 S 17.9 0.6 0:01.83 apache2
1657 www-data 20 0 396636 50116 25676 S 16.2 0.2 0:00.49 php
1408 www-data 20 0 4886932 140960 95820 S 13.9 0.6 0:01.19 apache2
1660 www-data 20 0 402604 54920 25552 R 13.6 0.2 0:00.41 php
1516 www-data 20 0 4887744 103544 59588 S 13.2 0.4 0:00.63 apache2
1662 www-data 20 0 395992 47992 25552 R 12.3 0.2 0:00.37 php
1405 www-data 20 0 4818300 102112 52156 R 10.9 0.4 0:00.58 apache2
1406 www-data 20 0 4889816 113576 65876 S 10.6 0.5 0:01.25 apache2
32289 www-data 20 0 4938324 347348 251720 S 9.6 1.4 0:20.38 apache2
1077 www-data 20 0 4894916 241332 188880 S 5.3 1.0 0:03.95 apache2
1518 www-data 20 0 4892348 129204 79324 S 4.0 0.5 0:01.66 apache2
1519 www-data 20 0 4888024 98812 54260 S 3.3 0.4 0:00.31 apache2
374 www-data 20 0 4891276 322388 272732 S 3.0 1.3 0:09.00 apache2
An explanation of thetopcommand generated output is as follows:
The$topcommand displays a lot ofinformationabout the running system.
The first line of the display is shown as follows:
top - 15:52:40 up 275 days, 1:27, 2 users, load average: 5.33, 4.59, 4.53
The description of fields in the first line is as follows:
- Current time
- System uptime
- Number of users logged in
- Load average of
5,10, and15minutes, respectively
The second line is shown as follows:
Tasks: 353 total, 10 running, 342 sleeping, 1 stopped, 0 zombie
This line shows the summary of tasks or processes. It shows the total number of all the processes, which includes the total number of running, sleeping, stopped, and zombie processes. The third line is shown as follows:
%Cpu(s): 32.5 us, 25.0 sy, 0.0 ni, 41.8 id, 0.0 wa, 0.0 hi, 0.6 si, 0.0 st
This line shows information about CPU usage as a % in different modes as follows:
* us (user): CPU usage in%for running (un-niced) user processes* sy (system): CPU usage in%for running kernel processes* ni (niced): CPU usage in%for running niced user processes* wa (IO wait): CPU usage in%waiting for IO completion* hi (hardware interrupts): CPU usage in%for serving hardware interrupts* si (software interrupts): CPU usage in%for serving software interrupts* st (time stolen): CPU usage in%for time stolen for this VM by the hypervisor
The fourth line is shown as follows:
KiB Mem : 24688724 total, 2805744 free, 1733244 used, 20149736 buff/cache
KiB Swap: 34552824 total, 34061312 free, 491512 used. 20726872 avail Mem
This line provides information about memory usage. It shows the physical memory that is used, free, available, and used for buffers. The next line shows the swap memory that is available, used, free, and cached.
After this line, we see the table of values with the following columns:
PID: This is the ID of the processUSER: This is the user that is the owner of the processPR: This is the priority of the processNI: This is theNICEvalue of the processVIRT: This is the virtual memory used by the processRES: This is the physical memory used for the processSHR: This is the shared memory of the processS: This indicates the status of the process:S= sleep,R= running, andZ= zombie (S)%CPU: This is the%of CPU used by this process%MEM: This is the%of RAM used by the processTIME+: This is the total time of activity of this processCOMMAND: This is the name of the process
Let’s take a look at the performance monitoring tools iostat, vmstat, and sar:
To view the statistics of the CPU and the input/output device’s utilization, use the following command:
$ iostat
Output:root@app:/home/satish$ iostat
Linux 4.4.0-116-generic (app) Wednesday 26 May 2021 _x86_64_ (12 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
19.78 0.00 4.90 0.08 0.00 75.24
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
loop0 0.00 0.00 0.00 5 0
scd0 0.00 0.00 0.00 96 0
sda 13.21 35.38 121.96 840773629 2898636144
root@app:/home/satish$
Shows only CPU statistics:
$ iostat -c
Shows onlydiskstatistics:
$ iostat -d
To view the virtual memory statistics, use the following command:
$ vmstat
Output:root@app:/home/satish$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
3 0 491524 8364608 8665900 6561112 0 0 3 10 0 0 20 5 75 0 0
root@app:/home/satish$
root@app:/home/satish$
This shows various event counters and memory statistics:
$ vmstat -s
Runs for every one second stop after executing for five intervals:
$ vmstat -t 1 5
This will show the CPU activity report three times every 2 seconds:
$ sar -u 2 3
Output:root@app:/home/satish$ sar -u 2 3
Linux 4.4.0-116-generic (app) Wednesday 26 May 2021 _x86_64_ (12 CPU)
05:50:51 IST CPU %user %nice %system %iowait %steal %idle
05:50:53 IST all 16.26 0.00 15.72 0.00 0.00 68.02
05:50:55 IST all 1.83 0.00 1.42 0.00 0.00 96.75
05:50:57 IST all 0.96 0.00 1.42 0.00 0.00 97.62
Average: all 6.36 0.00 6.19 0.00 0.00 87.44
root@app:/home/satish$