RHCSA Rapid Track
Course update
An updated version of this course is available that uses a newer version of Red Hat Enterprise Linux in the lab environment. Therefore, the RHEL 9.0 version of the lab environment will retire on December 31, 2024. Please complete any work in this lab environment before it is removed on December 31, 2024. For the most up-to-date version of this course, we recommend moving to the RHEL 9.3 version.
In this exercise, you adjust the scheduling priority of processes with the nice and renice commands, and observe the effects on process execution.
Outcomes
Adjust scheduling priorities for processes.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that all required resources are available.
[student@workstation ~]$ lab start tuning-procscheduling
Important
This exercise uses commands that perform an endless checksum on a device file and intentionally use significant CPU resources.
Instructions
Use the
sshcommand to log in to theserveramachine as thestudentuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$Determine the number of CPU cores on the
serveramachine, and then start two instances of thesha1sum /dev/zero &command for each core.Use the
grepcommand to parse the number of existing virtual processors (CPU cores) from the/proc/cpuinfofile.[student@servera ~]$
grep -c '^processor' /proc/cpuinfo2Use a looping command to start multiple instances of the
sha1sum /dev/zero &command. Start two instances for each virtual processor that was indicated in the previous step. In this example, aforloop creates four instances. The PID values in your output might vary from the example.[student@servera ~]$
for i in {1..4}; do sha1sum /dev/zero & done[1] 1132 [2] 1133 [3] 1134 [4] 1135
Verify that the background jobs are running for each of the
sha1sumprocesses.[student@servera ~]$
jobs[1]Runningsha1sum /dev/zero & [2]Runningsha1sum /dev/zero & [3]-Runningsha1sum /dev/zero & [4]+Runningsha1sum /dev/zero &Use the
psandpgrepcommands to display the percentage of CPU usage for eachsha1sumprocess.[student@servera ~]$
ps u $(pgrep sha1sum)USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND student 1132 49.6 0.1 225336 2288 pts/0 R 11:40 2:40 sha1sum /dev/zero student 1133 49.6 0.1 225336 2296 pts/0 R 11:40 2:40 sha1sum /dev/zero student 1134 49.6 0.1 225336 2264 pts/0 R 11:40 2:40 sha1sum /dev/zero student 1135 49.6 0.1 225336 2280 pts/0 R 11:40 2:40 sha1sum /dev/zeroTerminate all
sha1sumprocesses, and then verify that no jobs are running.Use the
pkillcommand to terminate all running processes with thesha1sumname pattern.[student@servera ~]$
pkill sha1sum[2]Terminatedsha1sum /dev/zero [4]+Terminatedsha1sum /dev/zero [1]-Terminatedsha1sum /dev/zero [3]+Terminatedsha1sum /dev/zeroVerify that no jobs are running.
[student@servera ~]$
jobs[student@servera ~]$
Start multiple instances of the
sha1sum /dev/zero &command, and then start one additional instance of thesha1sum /dev/zero &command with a nice level of 10. Start at least as many instances as the number of system virtual processors. In this example, three regular instances are started, plus another with a higher nice level.Use looping to start three instances of the
sha1sum /dev/zero &command.[student@servera ~]$
for i in {1..3}; do sha1sum /dev/zero & done[1] 1207 [2] 1208 [3] 1209Use the
nicecommand to start the fourth instance with a nice level of 10.[student@servera ~]$
nice -n 10 sha1sum /dev/zero &[4] 1210
Use the
psandpgrepcommands to display the PID, percentage of CPU usage, nice value, and executable name for each process. The instance with the nice value of 10 displays a lower percentage of CPU usage than the other instances.[student@servera ~]$
ps -o pid,pcpu,nice,comm $(pgrep sha1sum)PID %CPU NI COMMAND 1207 64.2 0 sha1sum 1208 65.0 0 sha1sum 1209 63.9 0 sha1sum12108.2 10 sha1sumUse the
sudo renicecommand to lower the nice level of a process from the previous step. Use the PID value of the process instance with the nice level of 10 to lower its nice level to 5.[student@servera ~]$
sudo renice -n 5[sudo] password for student:1210student(process ID) old priority 10,1210new priority 5Repeat the
psandpgrepcommands to display the CPU percentage and nice level.[student@servera ~]$
ps -o pid,pcpu,nice,comm $(pgrep sha1sum)PID %CPU NI COMMAND 1207 62.9 0 sha1sum 1208 63.2 0 sha1sum 1209 63.2 0 sha1sum1210 10.9 5 sha1sumUse the
pkillcommand to terminate all running processes with thesha1sumname pattern.[student@servera ~]$
pkill sha1sum...output omitted...Return to the
workstationmachine as thestudentuser.[student@servera ~]$
exitlogout Connection to servera closed. [student@workstation ~]$Important
Verify that you have terminated all exercise processes before leaving this exercise.
This concludes the section.