scheduling_examples.c - a C program that demonstrates the uses of functions mentioned in the Topic 9 lecture notes: sched_yield(), nice(), getpriority(), setpriority(), CPU_ZERO(), CPU_ISSET(), CPU_SET(), CPU_CLR(), sched_getaffinity(), sched_setaffinity(), sched_getscheduler(), sched_setscheduler(), memset(), sched_getparam(), sched_get_priority_min(), sched_get_priority_max(), sched_rr_get_interval(), setrlimit(), and getrlimit().
The command: gcc -Wall -Wextra -O2 -g -o scheduling_examples scheduling_examples.c
compiles the C source code located inside the file scheduling_examples.c. See more details here.
The command: sudo ./scheduling_examples
executes the program scheduling_examples as the root user. Not all users of Linux are allowed to elevate their privileges to those of the root, so calling sudo might not be permitted for your user. However, if you are the owner of a virtual machine, you can call sudo, type the password, and view the full execution of this program with no permission limitations.
When I run this command on my Linux virtual machine (I am allowed to use sudo,) I get the following output: The current nice value is: 0.
We increased the nice value to: 5.
The current nice value is: 5.
The new nice value is: 6.
cpu = 0 is set
cpu = 1 is set
cpu = 2 is unset
cpu = 3 is unset
cpu = 4 is unset
cpu = 5 is unset
cpu = 6 is unset
cpu = 7 is unset
cpu = 8 is unset
cpu = 9 is unset
cpu = 10 is unset
cpu = 11 is unset
cpu = 12 is unset
cpu = 13 is unset
cpu = 14 is unset
cpu = 15 is unset
This device allows checking up to 1024 CPUs.
cpu = 0 is set
cpu = 1 is unset
cpu = 2 is unset
cpu = 3 is unset
cpu = 4 is unset
cpu = 5 is unset
cpu = 6 is unset
cpu = 7 is unset
cpu = 8 is unset
cpu = 9 is unset
cpu = 10 is unset
cpu = 11 is unset
cpu = 12 is unset
cpu = 13 is unset
cpu = 14 is unset
cpu = 15 is unset
Policy is normal.
Policy was changed to round-robin.
Our priority is 1.
SCHED_RR priority range is: 1 - 99.
The time slice is 0 seconds and 100000000 nanosecs.
setrlimit: Operation not permitted
RLIMIT_NOFILE limits: soft = 1024 hard = 1048576.
The reason for the setrlimit: Operation not permitted error is due to a bug in earlier versions of sudo. The version of sudo that is installed on my virtual machine is 1.8.21p2, whereas the bug is fixed only in version 1.8.31p1 and above. I checked the version of the sudo command by typing: sudo -V into the terminal.
The command: ./scheduling_examples
executes the program scheduling_examples as your real user. Some of the function calls in this program might return errors because they require elevated permissions, which can only be achieved by calling sudo ./scheduling_examples.
Note: If you are a regular/unprivileged Linux user (for example, if you are using your Brooklyn College Linux Account,) you might have no permission to use the sudo command. No homework assignment or exam will ask you to use the sudo command, so don't worry about this current inability to use sudo. If you have access to a Linux virtual machine in which you are an administrator user, you should be able to use sudo.
The command: . ./.short_prompt
executes code inside a file named .short_prompt and sources it (applies all the changes to the current session.) See more details here.
The command: . ./.long_prompt
executes code inside a file named .long_prompt and sources it (applies all the changes to the current session.) See more details here.