You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
editing again lab4-advanced-system-process-monitoring.md
* translator found a few issues while translating
* fixes for some missing code blocks
* fixes for some contractions
* fixes for some variable use inconsistencies
Copy file name to clipboardExpand all lines: docs/labs/systems_administration_II/lab4-advanced_system_process_monitoring.md
+29-30Lines changed: 29 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
author: Wale Soyinka
2
+
author: Wale Soyinka
3
3
contributors: Steven Spencer, Ganna Zhrynova
4
4
tested on: All Versions
5
5
tags:
@@ -17,7 +17,6 @@ tags:
17
17
- cgroups
18
18
---
19
19
20
-
21
20
# Lab 4: Advanced System and process monitoring
22
21
23
22
## Objectives
@@ -52,7 +51,7 @@ The `fuser` command in Linux is used to identify processes using files or socket
52
51
touch ~/testfile.txt
53
52
```
54
53
55
-
2. Create the script that we will use to simulate access to testfile.txt. Type:
54
+
2. Create the script that we will use to simulate access to `testfile.txt`. Type:
56
55
57
56
```bash
58
57
cat >~/simulate_file_usage.sh <<EOF
@@ -87,7 +86,7 @@ The `fuser` command in Linux is used to identify processes using files or socket
87
86
fuser -v ~/testfile.txt
88
87
```
89
88
90
-
3. All done with testfile.txt and simulate_file_usage.sh. You can now remove the files. Type:
89
+
3. All done with `testfile.txt` and `simulate_file_usage.sh`. You can now remove the files. Type:
91
90
92
91
```bash
93
92
kill %1
@@ -145,11 +144,11 @@ The `fuser` command in Linux is used to identify processes using files or socket
145
144
146
145
!!! tip
147
146
148
-
The generate_cpu_load.sh script is a simple tool for generating CPU load by calculating Pi (π) to high precision. The same calculation is done 10 times. The script accepts an integer as the parameter for specifying the number of decimal places for calculating Pi.
147
+
The `generate_cpu_load.sh` script is a simple tool for generating CPU load by calculating Pi (π) to high precision. The same calculation is done 10 times. The script accepts an integer as the parameter for specifying the number of decimal places for calculating Pi.
149
148
150
149
#### To simulate extra CPU load
151
150
152
-
1. Let's run a simple test and calculate Pi to 50 decimal places. Run the Script by typing:
151
+
1. Run a simple test and calculate Pi to 50 decimal places. Run the Script by typing:
153
152
154
153
```bash
155
154
~/generate_cpu_load.sh 50 &
@@ -197,7 +196,7 @@ The `fuser` command in Linux is used to identify processes using files or socket
197
196
sudo perf stat -e cycles find /proc
198
197
```
199
198
200
-
3. Do the same thing but with the ./generate_cpu_load.sh script. Count specific events like CPU cycles to evaluate the performance of the ./generate_cpu_load.sh script. Type:
199
+
3. Do the same thing but with the `generate_cpu_load.sh` script. Count specific events like CPU cycles to evaluate the performance of the `generate_cpu_load.sh` script. Type:
201
200
202
201
```bash
203
202
sudo perf stat -e cycles ./generate_cpu_load.sh 500
@@ -222,7 +221,7 @@ The `fuser` command in Linux is used to identify processes using files or socket
222
221
223
222
!!! note
224
223
225
-
Here's the breakdown of the final sample output of the `perf stat` command:
224
+
Here is the breakdown of the final sample output of the `perf stat` command:
226
225
227
226
*1,670,638,886 cycles*: This indicates the total number of CPU cycles consumed during the execution of the script. Each cycle represents a single step in the CPU's instruction execution.
228
227
@@ -267,7 +266,7 @@ The `fuser` command in Linux is used to identify processes using files or socket
267
266
~/strace_script.sh &
268
267
```
269
268
270
-
2. Find the PID forthe `strace_script.sh` processin a separate terminal. Store the PID in a variable named MYPID. We'll use the `pgrep` command for this by running:
269
+
2. Find the PID forthe `strace_script.sh` processin a separate terminal. Store the PID in a variable named MYPID. Use the `pgrep`commandfor this by running:
271
270
272
271
```bash
273
272
export MYPID=$(pgrep strace_script);echo$MYPID
@@ -309,7 +308,7 @@ The `fuser` command in Linux is used to identify processes using files or socket
309
308
sudo timeout 10 strace -c -p $MYPID
310
309
```
311
310
312
-
Our sample system shows a summary report output like this:
311
+
Your sample system shows a summary report output like this:
313
312
314
313
OUTPUT:
315
314
@@ -538,7 +537,7 @@ This exercise demonstrates direct interaction with the `cgroup` v2 filesystem.
538
537
539
538
#### To set a new memory resource limit
540
539
541
-
1. Let's set a memory resource limit to limit memory usage to 4096 bytes (4kB). To restrict processes in the `cgroup` to use a maximum of 4kB of memory type:
540
+
1. Set a memory resource limit to limit memory usage to 4096 bytes (4kB). To restrict processes in the `cgroup` to use a maximum of 4kB of memory type:
542
541
543
542
```bash
544
543
echo 4096 | sudo tee /sys/fs/cgroup/exercise_group/memory.max
@@ -564,14 +563,14 @@ This exercise demonstrates direct interaction with the `cgroup` v2 filesystem.
564
563
565
564
#### To run and add process/script to the memory `cgroup`
566
565
567
-
1. Launch the memory_stress.sh, capture its PID and add the PID to cgroup.procs. Type:
566
+
1. Launch the `memory_stress.sh` script, capture its PID, and add the PID to `cgroup.procs`. Type:
568
567
569
568
```bash
570
569
~/memory_stress.sh &
571
570
echo $! | sudo tee /sys/fs/cgroup/exercise_group/cgroup.procs
572
571
```
573
572
574
-
The /sys/fs/cgroup/exercise_group/cgroup.procs file can be used for adding or viewing the PIDs (Process IDs) of processes that are members of a given `cgroup`. Writing a PID to this file assigns the ~/memory_stress.sh script process to the exercise_group `cgroup`.
573
+
Use /sys/fs/cgroup/exercise_group/cgroup.procs file for adding or viewing the PIDs (Process IDs) of processes that are members of a given `cgroup`. Writing a PID to this file assigns the `memory_stress.sh` script process to the `exercise_group``cgroup`.
575
574
576
575
2. The previous command will end very quickly before completion because it has exceeded the memory limits of the `cgroup`. You can run the following `journalctl`commandin another terminal to view the error as it happens. Type:
577
576
@@ -597,7 +596,7 @@ This exercise demonstrates direct interaction with the `cgroup` v2 filesystem.
597
596
echo 10000 | sudo tee /sys/fs/cgroup/exercise_group/cpu.max
598
597
```
599
598
600
-
10000 represents the CPU bandwidth limit. It's set to 10% of a single CPU core's total capacity.
599
+
10000 represents the CPU bandwidth limit. It isset to 10% of a single CPU core's total capacity.
601
600
602
601
2. Confirm CPU Limit has been set. Type:
603
602
@@ -646,14 +645,14 @@ This exercise demonstrates direct interaction with the `cgroup` v2 filesystem.
646
645
647
646
The primary storage device can be a target for setting I/O resource limits. Storage devices on Linux systems have major and minor device numbers that can be used to identify them uniquely.
648
647
649
-
1. First, let's create a set of helper variables to detect and store the device number for the primary storage device on the server. Type:
648
+
1. First, create a set of helper variables to detect and store the device number for the primary storage device on the server. Type:
650
649
651
650
```bash
652
651
primary_device=$(lsblk | grep disk | awk '{print $1}' | head -n 1)
@@ -682,7 +681,7 @@ The primary storage device can be a target for setting I/O resource limits. Stor
682
681
683
682
#### To create the I/O stress test process
684
683
685
-
1. Start a `dd` process to create a large file named /tmp/io_stress. Also, capture and store the PID of the `dd` process in a variable named `MYPID`. Type:
684
+
1. Start a `dd` process to create a large file named `/tmp/io_stress`. Also, capture and store the PID of the `dd` process in a variable named `MYPID`. Type:
@@ -705,7 +704,7 @@ The primary storage device can be a target for setting I/O resource limits. Stor
705
704
iotop -p $MYPID
706
705
```
707
706
708
-
The output will display I/O read/write speeds for the io_stress.sh process, which should not exceed 1 MB/s as per the limit.
707
+
The output will display I/O read/write speeds for the io_stress.sh process, which should not exceed 1 MB/s as per the limit.
709
708
710
709
#### To remove `cgroups`
711
710
@@ -731,7 +730,7 @@ CPU affinity binds specific processes or threads to particular CPU cores in a mu
731
730
lscpu | grep "On-line"
732
731
```
733
732
734
-
2. Let's create a sample process using the dd utility and store its PID in a MYPID variable. Type:
733
+
2. Create a sample process using the `dd` utility and store its PID in a `MYPID` variable. Type:
735
734
736
735
```bash
737
736
dd if=/dev/zero of=/dev/null & export MYPID="$!"
@@ -750,7 +749,7 @@ CPU affinity binds specific processes or threads to particular CPU cores in a mu
750
749
pid 1211483's current affinity mask: f
751
750
```
752
751
753
-
The output shows the CPU affinity mask of the process with a PID of 1211483 ($MYPID), represented in hexadecimal format. On our sample system, the affinity mask displayed is "f", which typically means that the process can run on any CPU core.
752
+
The output shows the CPU affinity mask of the process with a PID of 1211483 (`$MYPID`), represented in hexadecimal format. On our sample system, the affinity mask displayed is "f", which typically means that the process can run on any CPU core.
754
753
755
754
!!! note
756
755
@@ -765,7 +764,7 @@ CPU affinity binds specific processes or threads to particular CPU cores in a mu
765
764
766
765
### To set/change CPU affinity
767
766
768
-
1. Set the CPU affinity of the dd process to a single CPU (CPU 0). Type:
767
+
1. Set the CPU affinity of the `dd` process to a single CPU (CPU 0). Type:
769
768
770
769
```bash
771
770
taskset -p 0x1 $MYPID
@@ -784,9 +783,9 @@ CPU affinity binds specific processes or threads to particular CPU cores in a mu
784
783
taskset -p $MYPID
785
784
```
786
785
787
-
The output indicates the CPU affinity mask of the process with PID $MYPID. The affinity mask is "1" in decimal, which translates to "1" in binary. This means that the process is currently bound to CPU core 0.
786
+
The output indicates the CPU affinity mask of the process with PID `$MYPID`. The affinity mask is "1"in decimal, which translates to "1"in binary. This means that the process is currently bound to CPU core 0.
788
787
789
-
3. Now, set the CPU affinity of the dd process to multiple CPUs (CPUs 0 and 1). Type:
788
+
3. Now, set the CPU affinity of the `dd` process to multiple CPUs (CPUs 0 and 1). Type:
790
789
791
790
```bash
792
791
taskset -p 0x3 $MYPID
@@ -809,7 +808,7 @@ CPU affinity binds specific processes or threads to particular CPU cores in a mu
809
808
810
809
5. Launch either the `top` or `htop` utility in a separate terminal and observe if you see anything of interest as you experiment with different `taskset` configurations for a process.
811
810
812
-
6. All done. Use its PID ($MYPID) to kill the `dd` process.
811
+
6. All done. Use its PID (`$MYPID`) to kill the `dd` process.
813
812
814
813
## Exercise 9
815
814
@@ -849,18 +848,18 @@ This exercise shows how to use `systemd-run` for creating transient service unit
849
848
850
849
!!! tip
851
850
852
-
`systemd.resource-control` is a configuration or management entity (concept) within the `systemd` framework designed for controlling and allocating system resources to processes and services. And `systemd.exec` is a `systemd` component responsible for defining the execution environment in which commands are executed. To view the various settings (properties) you can tweak when using systemd-run consult the `systemd.resource-control` and `systemd.exec` manual pages. This is where you will find documentation for properties like MemoryMax, CPUAccounting, IOWeight, etc.
851
+
`systemd.resource-control` is a configuration or management entity (concept) within the `systemd` framework designed forcontrolling and allocating system resources to processes and services. And `systemd.exec` is a `systemd` component responsible for defining the execution environmentin which commands are run. To view the various settings (properties) you can tweak when using `systemd-run` consult the `systemd.resource-control` and `systemd.exec` manual pages. This is where you will find documentation for properties like MemoryMax, CPUAccounting, IOWeight, etc.
853
852
854
853
#### To set CPU resource limit for a transient service
855
854
856
-
1. Let's create a transient `systemd` unit called "myrealtime.service". Run myrealtime.service with a specific round robin (rr) scheduling policy and priority. Type:
855
+
1. Create a transient `systemd` unit called "myrealtime.service". Run `myrealtime.service` with a specific round robin (rr) scheduling policy and priority. Type:
2. View the status formyrealtime.service. Also, capture/store the main [sleep] PIDin a MYPID variable. Type:
862
+
2. View the status for`myrealtime.service`. Also, capture/store the main [sleep] PIDin a MYPID variable. Type:
864
863
865
864
```bash
866
865
MYPID=$(systemctl status myrealtime.service | awk '/Main PID/ {print $3}')
@@ -906,7 +905,7 @@ This exercise shows how to use `systemd-run` for creating transient service unit
906
905
907
906
### `schedtool`
908
907
909
-
This exercise demonstrates the use of `schedtool` to understand and manipulate process scheduling in Rocky Linux. We will also create a script to simulate a process for this purpose.
908
+
This exercise demonstrates the use of `schedtool` to understand and manipulate process scheduling in Rocky Linux. You will also create a script to simulate a process for this purpose.
910
909
911
910
#### To install `schedtool`
912
911
@@ -938,15 +937,15 @@ This exercise demonstrates the use of `schedtool` to understand and manipulate p
938
937
~/cpu_load_generator.sh & echo $!
939
938
```
940
939
941
-
3. Capture the PID forthe main `openssl` process launched within the cpu_load_generator.sh script. Store the PIDin a variable named MYPID. Type:
940
+
3. Capture the PID forthe main `openssl` process launched within the `cpu_load_generator.sh` script. Store the PIDin a variable named `$MYPID`. Type:
942
941
943
942
```bash
944
943
export MYPID=$(pidof openssl);echo$MYPID
945
944
```
946
945
947
946
#### To use `schedtool` to check the current scheduling policy
948
947
949
-
1. Use the `schedtool`command to display the scheduling information of the process with PID $MYPID. Type:
948
+
1. Use the `schedtool`command to display the scheduling information of the process with PID `$MYPID`. Type:
0 commit comments