| M01:
Introduction to Operating Systems |
TU1: Installing, configuring and exploiting
a computer system |
ASIX1 |
Practical Exercise 9: Managing processes | 2-2-12 |
Practical Exercise 9: Managing processes
During its lifetime, a process needs system resources such as the
CPUs in the system to run its instructions or the system's physical
memory or RAM to hold its data and code. Another kind of resources can
be files in a storage device (hard disk, USB pendrive,....) or physical
devices in the system such as a sound card. The allocation of proper
resources to each process running in the system is a duty of Linux.
Another duty of the operating system is to avoid that a single process
monopolizes the most of the CPU time and RAM's space.
Linux is a multiprocessing operating system and therefore,
many processes are kept in memory at the same time. Usually there are
more process running that CPUs in the system. Due to it, the
processes have to share the CPUs time, being the operating
system who decides what process is executed in each moment. The part of
the operating system responsible for allocating CPU time to each
proccess is called the scheduler or scheduling system.
The scheduler is able to assign priorities to process. The higher
a process priority is, the higher will be its CPU time.
In Linux, a process has a series of characteristics. The following are the most important:
a) The process
ID or PID:
A unique identification number used to refer to the process. As long as
the process exists, it keeps the same PID number. Different processes
of the same program have different PIDs. When a process is ended, its
PID is freed and eventually the operating system can assign this number
to another process.
b) The
parent process ID or PPID: the number of the process (PID) that started
this process.
c) Nice number: It is the degree of friendliness or niceness of
this process toward other processes. This number is closely related to process
priority. The higher the nice number is, the lower the priority of the process is.
d) Real User ID or RUID: The owner of the process, i.e., the user issuing the command.
e) Effective User ID or EUID: The one
determining access and permissions to system resources. RUID and EUID are usually the
same user.




| Signal name | Signal number | Meaning |
|---|---|---|
| SIGTERM | 15 | Terminate the process in an orderly way (By default, if no signal is written, the kill command send the SIGTERM signal to a process). |
| SIGINT | 2 | Interrupt the process. A process can ignore this signal. |
| SIGKILL | 9 | Interrupt the process. A process can not ignore this signal. |
| SIGHUP | 1 | For daemons: reread the configuration file. |
To kill a process you need to know its PID. The ps command can provide you this information.
The synopsis of the kill command is : kill <-SIGNAL> PID.


The basic synopsis of the kill command is : killall <-SIGNAL> program_name(s). Signals can be specified either by name (e.g. -SIGKILL ) or by number (e.g. -9). A killall process never kills itself (but may kill other killall processes).
The next example shows how we can run the killall command to end all instances of the geany text editor:

4.1- Displaying the nice value
option with a positive value ==> The nice values is increased
==> The priority of your process is descreased.
option with a negative value ==> The nice values is decreased
==> The priority of your process is increased.Opposite to nice, renice
works with absolute priority positive value. The written value written
will be the value assigned directly to the process' nice value.You can use GNOME System monitor to change the priority of the process. Launch System Monitor from System > Administration > System Monitor and go to the Processes tab as shown in the following screenshot:

Now, you will be able to see the Nice column in front of every process. It basically specifies the priority value of the process. You can change priority of any process by right clicking the Nice column value and choosing Change Priority as shown in the following screenshot.

Thats all, adjust the new priority value and click Change Priority.

PRACTICAL EXERCISE
1- Open the terminal. Find out its PID and name using the ps command and the GNOME System Monitor. Is there any difference between PID given by the command and the GUI program?. Why?
2- Run a command to show only
the relevant information about the terminal process. What is the
problem with this command?. How would you avoid that problem?
3- End the terminal process using the GNOME System Monitor.
4- Open the terminal. Find out
its PID. Compare its current PID and the PID found in the 1st question.
Is there any difference between them? Why?.
5- End the terminal process using the kill command.
6- Start the OpenOffice Word Processor. Using the ps command, show information about the
process ID, effective user (number and name), % of CPU time and % of
RAM
allocated to the process and command name (with
arguments). Write some text in the new document. Do not save the text.
End the process using the kill command. Start the OpenOffice Word
process and the System recovery process. Have you recovered the text
written? Why?.
7- Open the OpenOffice Word
Processor. Open a termional and change to user fje. As fje user, find
out the PID and user ID of the OpenOffice Word Processor. Try to
kill the process. Are you able to kill it? Why?.
8- Become another time your "by default" user. Change to root. As root user, find
out the PID and user ID of the OpenOffice Word Processor. Try to kill
the process. Are you able to kill it? Why?.
9- As
root user, find
out the PID and user ID of the cups server. End the cups server
using the command kill and the signal SIGHUP. Is there any change
in the PID process?. Why?.
10- End the cups server using the command kill and the signak SIGTERM. Check if the process has been ended.
11- Start three instances of geany text editor and two new instances of GNOME system editor. End these 5 processes using their names and one only command. Check the result of your command.
12- Start geany. Working with the terminal and as a regular user (your user by default) check its nice value by default. Check the nice value of geany using the GNOME System Monitor. Is there any difference between the nice value given by the command and the GUI program?. Why?.
13- As a regular user, start a new instance of geany with an increase in its default nice value equal to 7. Check if geany is running with the new nice value. Have you had any problem? Why?.
14- As a regular user, start a new instance of geany with a decrease in its default nice value equal to 6. Check if geany is running with the new nice value. Have you had any problem? Why?.
15- As root user , start a new instance of geany with a decrease in its default nice value equal to 6. Check if geany is running with the new nice value. Have you had any problem? Why?.
16- As root user, close all instances of the geany program.
17- As a regular user, start a new instance of geany
with an increase in its default value equal to 3. Now, try to change
its nice value to -10. Are you able to change the nice value of geany? Why?.
18- As a regular user, start a new instance of geany
with an increase in its default value equal to 7. Now, try to change
its nice value to 2. Are you able to change the nice value of geany? Why?.
19- As a root user, change the nice value of the process geany started in the previous question. Try to change its nice value to -13. Are you able to change the nice value of geany? Why?.
20- As a regular user, start a new instance of geany
with an increase in its default value equal to 7. Now, try to change
its nice value to 2 using the GNOME Monitor System. Are you able to change the nice value of geany? Why?.
21- Now, try to change
its nice value to -4 using the GNOME Monitor System. Are you able to change the nice value of geany? Why?.
22- Find out two different ways of changing the nice value using the GNOME Monitor System.