- Process owner
- Memory and CPU usage
- Process identifier or PID
- The parent process identifier or PPID
- Process priority or niceness
- Process state
- Starting time/data of the process
and cumulative cpu time
EH1:
Linux Lab |
ASIX/DAW/DAM-1 |
Task A2: Managing processes | 19-2-24 |
Task
A2: Managing processes
3.- During its lifetime, a process
needs system resources such as the CPU time and RAM to hold
its code. The allocation of proper resources to each
process running in the system is a duty of Linux.
4.- Other resources a process could need are access to: hardware, physical or logical ports, reserved memory areas, files, directories, etc...
5.- The process
table on Linux holds information about the processes
that are currently handled by the OS. Each process is
represented as an entry (or process slot) in
the process table. Information hold
in the process table includes (but not only):
6.- Linux is a multiuser and
multiprocessing operating system and therefore, multiple users
can be running one or more processes on the system at the same
time. That means the operating system needs to identify each
process. A process is identified by its Process ID
also called PID and by its Parent
Process ID also called PPID.
7.- A PID must be a unique
identification number for each process running on the system.
Processes can NOT share PID. As long as the process exists, it
keeps the same PID number. When a process is ended,
its PID is freed and eventually the operating system can
assign this number to another process.
a) Running
or Runnable (R):
b)
Interruptible Sleep (S):
c)
Uninterruptible Sleep (D):
d) Stopped
(T):
e) Zombie (Z):
f) Idle Kernel threads (I):
kill
command.
Asks the process to terminate voluntarily. Terminate the process in an
orderly way. Default option<Ctrl>+C
in the terminal. It interrupts the current
command processing and wait for user's next command.
command. Some daemons
repurpose this signal to trigger a configuration reload
without stopping its execution.<Ctrl>+D
in
the terminal. It terminates the
process (like SIGTERM) but also causes the shell to write
a core file to help the so-called post-mortem debug.
Signal name | Signal number | Meaning |
---|---|---|
SIGTERM | 15 | Terminates
or Ends the process in an orderly way and
sometimes executes a clean-up routine before exiting. By
default, if no signal is written, the kill command send
the SIGTERM signal to a process. Terminate or End are
synonymous when we talk about processes. |
SIGKILL | 9 | Interrupts
and Terminates immediately the process. A process can
not ignore this signal. It
does not permit to the process to do any action while
closing. It is a last resort signal and it is used when
SIGTERM or SIGQUIT are ignored by a process and do not
work. |
SIGHUP |
1 |
Reload configuration of
some daemons without stopping its execution. Disconnects
a process from its parent process |
SIGINT |
2 | Generated when the user
type <Ctrl>+C
in the terminal. It interrupts the current
command processing and wait for user's next command. Some processes are designed to never quit
until you send them a SIGINT to stop. |
SIGQUIT |
3 |
Generated when the user
type <Ctrl>+D
in the terminal. It
terminates the process (like SIGTERM) but also causes
the shell to write a core file to help the so-called
post-mortem debug. |
SIGSTOP |
19 |
Suspend the process
execution, putting it in stopped
state. |
SIGCONT |
18 |
If a process is in
stopped state, it will put it back in the running/runnable state and resume it
execution. |
The synopsis of the kill
command is : kill
<-SIGNAL> PID.
NOTE: The killall
command is part of a package called psmisc. If you
can not run killall because this commnad is not found on
your system then, install psmic.
The basic synopsis of the kill command is : killall <-SIGNAL> process_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:6.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.1- Start geany. Displays information about: the process owner, % of CPU time and % of memory space allocated to the process, Virtual memory size (vsz) and RAM memory allocated, Process ID and parent process ID, Nice number, State of the process, what time the command was started and acumulative CPU time and program/command name.
2- Open a new instance of geany. Find
out its PID and PPID:
a) Compare the PID found in the 2nd
question and the PID found in the 1st question. Is there
any difference between them? Why?.
b) Compare
the PPID found in
the 2nd question and the PPID found in the 1st
question. Is there any difference between them?
Why?.
3- Using the terminal: End
the processes
started in question 1 and 2 in an
orderly and safe way.
4- Start a GUI program called MATE
System Monitor (Applications -> System Tools -> Mate
System Monitor). Display basic information about
the process.
5- Open a terminal.
Become user fje. As fje user, find out the PID
of the process started in question 4. Try to end the process in an orderly and safe
way. Are you
able to end the process?. Why?.
6-
Become again your "by default" user. Find out the PID of the process started in question 4.
Try to end the process in an
orderly and safe way.
Are you able to end the process? Why?.
7- Start 4 instances of geany text editor and 3
new instances of Atril (the default pdf reader that you
can find in Applications --> Office). Check the 7 processes where
started. Show basic information only about the 7 processes
started with the help of grep. Do not show the
process grep.
Help 1: -E '(geany|atril)' to show geany
and atril.
Help 2:
-v to not show grep.
8- End these 7 processes started in question 7 using
their names and one only command.
9- Find
out the PID and user owner of the
sshd process. Try to end the sshd.
What happens?. Why?.
10- As root user, find out the PID and
user ID of the sshd process. Try to end
the sshd process using the command with the signal SIGHUP.
What happens?. Why?.
11- As
root user, try to end the sshd
process using the signal SIGTERM. What happens?. Why?..
12- Start geany. Find
out the PID number and the process name of the
new geany's instance in the process
table.Now:
a) Stops geany. Show its state.
b) Try to create a new file. What
happens?. Why?
13- Put back geany
to the Run/Runnable state. What happens now?. Can
you create new files?.
14- Start a new instance of geany from your
terminal. Send the SIGINT signal to geany.
Show the state of your terminal after sending the SIGINT
signal.
15- Start a new instance of nano in the background.
Show a list of processes started by your user to the background.
16- Move nano to the foreground.
17- Run the command sleep
100000 in the background. Show a list of processes started by your user
to the background. Check the process identifier
and state.
18- Stop the process started in
question 17
19- As a regular user,
start a new instance of geany with
an increase in its default nice value equal to 9.
Check if geany is
running with the new nice value. Have you had any
problem? Why?.
20- As a regular user, start a new instance of geany with a
decrease in its default nice value equal to 5. Check if geany is running with the
new nice value. Have you had any problem? Why?.
21- As root
user , start a new instance of geany with a
decrease in its default nice value equal to 9.
Check if geany is
running with the new nice value. Have you had any
problem? Why?.
22- As root
user, close all instances of the geany program.
23- As a regular user, start a new instance of geany with an increase in
its nice default value equal to 2. Now, try to change its nice
value to -8. Are you able to change the nice value of geany? Why?.
24- As a regular user, start a new instance of geany with an increase in
its nice default value equal to 6. Now, try to change its nice
value to 3. Are you able to change the nice value of geany? Why?.
25- As a root
user, change the nice value of the process geany started in the
previous question. Try to change its nice value to -11. Are you able to change the nice value of geany? Why?.
26- Download http://www.collados.org/asix1/eh1/q26.c
and:
a) Compile q26.c running:
gcc q26.c -o q26.
Run q26.
b) Open a new termimal.
Run: ps -eo
user,pid,ppid,state,command | grep
q26 | grep -v grep
c) How many q26 processes
are running in the system?
d) Is any of them a zombie
process?. How do you know it?
e) Try to send the SIGTERM or SIGKILL
to the q26 zombie process. Does it work?. Why?
f) When will the q26 zombie
process be removed from the process table?
27- Download http://www.collados.org/asix1/eh1/q27.c
and:
a) Compile q27.c
running: gcc q27.c
-o q27. Run q27.
b) Run: ps
-eo user,pid,ppid,state,command |
grep q27 | grep -v grep
c) Can you find any instance of q27
that has become a orphan process?. How do you know it?
d) When will the q27
orphan process be removed from the process table?
e) Try to send the SIGTERM
or SIGKILL to the q27 orphan process.
Does it work?. Why?