RHCSA Rapid Track
In this exercise, you will experience the influence that nice levels have on relative process priorities.
| Resources | |
|---|---|
| Machines: | desktopX |
Outcomes
An interactive tour of the effects of nice levels.
None
Log in as
studentto yourdesktopXsystem.Using the special file
/proc/cpuinfo, determine the number of CPU cores in yourdesktopXsystem, then start two instances of the command sha1sum /dev/zero & for each core.To determine the number of cores using
/proc/cpuinfo:[student@desktopX ~]$NCORES=$( grep -c '^processor' /proc/cpuinfo )Either manually or with a script, start two sha1sum /dev/zero & commands for every core in your system.
Note
The seq command prints a list of numbers.
[student@desktopX ~]$for I in $( seq $((NCORES*2)) )>do>sha1sum /dev/zero &>done
Verify that you have all the background jobs running that you expected (two for every core in your system).
[student@desktopX ~]$jobs[1]- Running sha1sum /dev/zero & [2]+ Running sha1sum /dev/zero & ...
Inspect the CPU usage (as a percentage) of all your sha1sum processes, using the ps and pgrep commands. What do you notice?
[student@desktopX ~]$ps u $(pgrep sha1sum)The CPU percentage for all sha1sum processes is about equal.
Use the killall command to terminate all your sha1sum processes.
[student@desktopX ~]$killall sha1sum
Start two sha1sum /dev/zero & commands for each of your cores, but give exactly one of them a nice level of
10.[student@desktopX ~]$for I in $( seq $((NCORES*2-1)) )>do>sha1sum /dev/zero &>done[student@desktopX ~]$nice -n10 sha1sum /dev/zero &
Using the ps command, inspect the CPU usage of your sha1sum commands. Make sure you include the nice level in your output, as well as the PID and the CPU usage. What do you notice?
[student@desktopX ~]$ps -o pid,pcpu,nice,comm $(pgrep sha1sum)The instance of sha1sum with the nice level of
10gets significantly less CPU than the other instance(s).
Use the renice command to set the nice level of the sha1sum with a nice level of
10down to5. The PID should still be visible in the output of the previous step.Did this work? Why not?
[student@desktopX ~]$renice -n 5renice: failed to set priority for<PID><PID>(process ID): Permission deniedUnprivileged users are not allowed to set negative nice values or lower the nice value on an existing process.
Using the sudo and renice commands, set the nice level for the process you identified in the previous step to
-10.[student@desktopX ~]$sudo renice -n -10<PID>
Start the top command as
root, then use top to lower the nice level for the sha1sum process using the most CPU back down to0. What do you observe afterwards?[student@desktopX ~]$sudo topIdentify the sha1sum process using the most CPU. It will be near the top of the screen.
Press r to enter renice mode, then enter the PID you identified, or press Enter if the offered default PID is the one you want.
Enter
0, then press Enter.All sha1sum commands are again using an (almost) equal amount of CPU.
Important: Clean up by exiting top and killing all your sha1sum processes.
Press q to exit top.
[student@desktopX ~]$killall sha1sum