In this exercise, you will adjust the scheduling priority of processes with the nice and renice commands and observe the effects this has on process execution.
Outcomes
You should be able to adjust scheduling priorities for processes.
Log in as the student user on workstation using student as the password.
From workstation, run the lab tuning-procscheduling start command.
The command runs a start script to determine if the servera host is reachable on the network.
[student@workstation ~]$lab tuning-procscheduling start
From workstation use SSH to log in to servera as the student user.
The systems are configured to use SSH keys for authentication, so a password is not required.
[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$
Determine the number of CPU cores on servera and then start two instances of the sha1sum /dev/zero & command for each core.
Use grep to parse the number of existing virtual processors (CPU cores) from the /proc/cpuinfo file.
[student@servera ~]$grep -c '^processor' /proc/cpuinfo2
Use a looping command to start multiple instances of the sha1sum /dev/zero & command. Start two per virtual processor found in the previous step. In this example, that would be four instances. The PID values in your output will vary from the example.
[student@servera ~]$for i in $(seq 1 4); do sha1sum /dev/zero & done[1] 2643 [2] 2644 [3] 2645 [4] 2646
Verify that the background jobs are running for each of the sha1sum processes.
[student@servera ~]$jobs[1]Runningsha1sum /dev/zero & [2]Runningsha1sum /dev/zero & [3]-Runningsha1sum /dev/zero & [4]+Runningsha1sum /dev/zero &
Use the ps and pgrep commands to display the percentage of CPU usage for each sha1sum process.
[student@servera ~]$ps u $(pgrep sha1sum)USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND student 264349.80.0 228360 1744 pts/0 R 11:15 6:09 sha1sum /dev/zero student 264449.80.0 228360 1780 pts/0 R 11:15 6:09 sha1sum /dev/zero student 264549.80.0 228360 1748 pts/0 R 11:15 6:09 sha1sum /dev/zero student 264649.80.0 228360 1780 pts/0 R 11:15 6:09 sha1sum /dev/zero
Terminate all sha1sum processes, then verify that there are no running jobs.
Use the pkill command to terminate all running processes with the name pattern sha1sum.
[student@servera ~]$pkill sha1sum[2]Terminatedsha1sum /dev/zero [4]+Terminatedsha1sum /dev/zero [1]-Terminatedsha1sum /dev/zero [3]+Terminatedsha1sum /dev/zero
Verify that there are no running jobs.
[student@servera ~]$jobs[student@servera ~]$
Start multiple instances of sha1sum /dev/zero &, then start one additional instance of sha1sum /dev/zero & with a nice level of 10. Start at least as many instances as the system has virtual processors. In this example, 3 regular instances are started, plus another with the higher nice level.
Use looping to start three instances of sha1sum /dev/zero &.
[student@servera ~]$for i in $(seq 1 3); do sha1sum /dev/zero & done[1] 1947 [2] 1948 [3] 1949
Use the nice command to start the fourth instance with a 10 nice level.
[student@servera ~]$nice -n 10 sha1sum /dev/zero &[4] 1953
Use the ps and pgrep commands to display the PID, percentage of CPU usage, nice value, and executable name for each process. The instance with the nice value of 10 should display a lower percentage of CPU usage than the other instances.
[student@servera ~]$ps -o pid,pcpu,nice,comm $(pgrep sha1sum)PID %CPU NI COMMAND 1947 66.0 0 sha1sum 1948 65.7 0 sha1sum 1949 66.1 0 sha1sum1953 6.7 10 sha1sum
Use the sudo renice command to lower the nice level of a process from the previous step. Note the PID value from the process instance with the nice level of 10. Use that process PID to lower its nice level to 5.
[student@servera ~]$sudo renice -n 51953[sudo] password for student:student1953(process ID) old priority 10,new priority 5
Repeat the ps and pgrep commands to redisplay the CPU percent and nice level.
[student@servera ~]$ps -o pid,pcpu,nice,comm $(pgrep sha1sum)PID %CPU NI COMMAND 1947 63.8 0 sha1sum 1948 62.8 0 sha1sum 1949 65.3 0 sha1sum1953 9.1 5 sha1sum
Use the pkill command to terminate all running processes with the name pattern sha1sum.
[student@servera ~]$pkill sha1sum...output omitted...
Exit from servera.
[student@servera ~]$exitlogout Connection to servera closed.[student@workstation ~]$