Process Management:
Everything that happens on a Linux server, a process is started. For that reason,
process management is among the key skills that an administrator has to master.
There is Three Types of Process running in RHEL Linux:
1. Shell Jobs (commands started from the command line also called interactive
jobs).
2. Daemons (processes that provide services. They normally are started when
a computer is booted).
3. Kernel Threads (essential kernel threads that are started as real-time processe).
HINT
Modern Linux kernels differentiate between essential kernel threads that are
started as real-time processes and normal user processes. Increasing the priority of a
user process will never be able to block out kernel threads or other
processes that were started as real-time processes.
Using ps to get process information:
As you can see ps command has two flavors
BSD options written without hyphens and linux flavor.
How to Differentiate Between the three types of shell Jobs ?!!
a. Shell jobs is a command run from a shell
b. Daemons is ended by d letter like (httpd – dhcpd – named) and of course the
most important is the process with PID 1 which is system.
c. Kernel threads between square brackets like the process with PID 2 which is
kthreadd.
Managing Shell Jobs
each and every command written on a shell is a shell job that means the shell is a
parent and your command is the child … (remember this)
Shell jobs occupying the terminal it was started from until it has finished its work. If
this job will take longer time then you can change the default behavior from
foreground to background.
For example if you type a command like :
#ls -l / it will run in foreground and displaying the content of / directory
But if you call application from the shell like firefox
#firefox
You will notice that the application is started but you are no longer able to run any
command again on the shell screen so here you can decide to run the application in
background to get your terminal back again.
HOW ?!!!!
By end your command with &
#firefox&
#gedit&
Ctrl+Z to temporarily stop the job. This does not remove the job from memory; it just
pauses the job so that it can be managed.
Ctrl+C This stops the current job and removes it from memory.
Ctrl+D, which sends the End Of File (EOF) character to the current job.
These abbreviations are so good for foreground processes, but to manage the
background processes you can bring them back to foreground and run one of the
previous abbreviations.
#jobs to display background processes
#fg %<index> to bring to foreground
Or
Use the kill command (we will discuss later).
Parent and Child Relationship:
As wen mentioned earlier in this document the shell is the parent and the command is
the child.
The relationship is:
1. For foreground process if you kill the parent it will kill the child.
2. For background process if you kill the parent the child in still running because his
parent will be system.
Use ps -ef to See the Exact Command Used to Start Processes
Sending Signals to Processes with kill, killall, and pkill
kill command or sending other signals to processes, it is good to know that Linux
processes have a hierarchical relationship.
■ The signal SIGTERM (15) is used to ask a process to stop. (default signal)
■ The signal SIGKILL (9) is used to force a process to stop.
■ The SIGHUP (1) signal is used to hang up a process. The effect is that the
process will reread its configuration files, which makes this a useful signal to
use after making modifications to a process configuration file.
#kill <PID> each process has it’s ID
#kill <PPID>
How we know the PID or the PPID ?!! from ps aux or ps -ef .
Or pgrep or pidof commands but the recommended is ps -ef as we mention in process
management lecture.
Kill with pkill <PROCESS> is not recommended.
Using top to Manage Processes
Priorities ( 0 Normal , -20 highest , 19 lowest)
. From top, type k. top will
then prompt for the PID of the process you want to send a signal to. By default, the
most active process is selected. After you enter the PID, top asks which signal you
want to send. By default, signal 15 for SIGTERM is used. However, if you want to
insist a bit more, you can type 9 for SIGKILL. Now press Enter to terminate the
process.
To renice a running process from top, type r. You are first prompted for the PID
of the process you want to renice. After entering the PID, you are prompted for the
nice value you want to use. Enter a positive value to increase process priority or a
negative value to decrease process priority.
Using nice and renice commands
#nice -n -15 firefox
#renice -n 9 8875
مراجعة المحا ة لمعرفة ناتج تنف ذ اي امر من اﻻوامر السا قة ير
Eng. Muhammad Adel