Introduction to Process Management
Processes on computer systems are nothing but the applications or programs which are running.
In this lesson we will learn how to see those processes, manage processes i.e kill, change priorities etc
Lets start with the ps
command
ps
ps gives you the information of all the current processes running in the system
lets see some of the examples
As you can see it displays Process ID (PID), Terminal (TTY) from which its running and time(TIME) since process has been running CMD is nothing but command which started this process.
To see all the processes started by all users you can use -A option. You can also use -e option to do the same job as -A
As you can notice PID 1 is for system processes which started the OS itself
You can also use ps -ax to see all the processes running. This is BSD format, it will also show the state of the process
To see more information of process you can also use ps aux which will give you information about user who started it, how much is memory consumption etc
You can get more information about various advanced options using man command
You can following command
List processes by user
|
|
Display certain columns
|
|
Display how much time process is running, run these command and find out meaning of each option we have specified
|
|
pstree
This command is useful if you find out the processes relationships, You can clearly see the parent and child processes.
|
|
You can use various options like ps -t
to display threads information, ps -p
to display the process ids.
You can also see the owners of the processes using -u option.
If you want to process tree of a specific user then use ps username
.
nice and renice
Nice command allows you to change the priority of the process. Every process have a scheduling priority in the system. Using the nice command you can change the scheduling priority of the process.
Simple way to check the nice value of the process is to use top or htop command as shown below
|
|
As you can see in fourth column nice value is 0 for process 33697 process ID
You can also check NI value using ps -l
Highest priority process can have -20 and lowest can have +19, default priority fr user created process is 0
You can check default nice value set for you using simple nice
command also as shown below
You can set the nice value as shown below
|
|
Firefox process will be started with 10 nice value you can verify it using
|
|
You can start the process with a specified priority but what if you want to change the priority of already running process, to do this we use renice command
Note you need sudoers permission to use this command
-n is to specify the priority and -p is specify the process id of the running process.
kill
Kill command is siply used to terminate the running processes. You need to know the process id to kill the process.
Using ps aux and filtering it easily find out the process ID or you can also make use of pidof command with application name to find out pid of process
as shown below
|
|
Finding PID Using grep and filter
To kill simply use kill and PID
pkill
pkill works similar to kill but it takes the name of the progrma instead of the process id
|
|
killall
killall like other kill commands will kill all the process matching the name of the processes
|
|
Note kill commands kills only one process whereass killall kills multiple processes
xkill
xkill is used to kill the graphical applications
when run on the terminal it allows you to select the window and kill it using the mouse.
bg, fg and jobs
bg command is used to send the job in the background fg is to get the job in the foreground and jobs will display all the jobs which are currently running in the background
Lets do some experiments
Step 1 : Start applications or processes from the terminal
|
|
It will open gedit application but in the foreground. The teminal is occupied so lets stop the application using Ctr + Z
and then
execute the bg command to put it in the background
as shown below
You can see the [1] job is running in the background
similarly we can put the firefox in the background and then we use jobs command to see how many jons are running in the background
You can now bring the any application using the number into foreground
using following command
pgrep
pgrep command is used to find the process Id matching the supplied name
following are the some of the examples
We can also use the -u option to specify the user whose processes we care interested in