Linux Lecture 20
Linux Lecture 20
ADMINISTRATION
Lecture – 20
Background
processes
By : Naveen Tiwari
1
Processes
• Everything that you run in Linux is a process.
• Whenever a command runs in Linux, it creates/starts a new
process.
• Eg: ls a process starts.
• A 5 digit ID number Linux keeps an account of the processes, this
number is called process ID or PID.
• Eg: PID -20968
• Each process in the system has a unique PID.
• Used up pid’s can be used in again for a newer process since all
the possible combinations are used.
• No two processes with the same pid exist in the system at a time
because it is the pid that Unix uses to track each process.
Initializing a process
• There are 2 methods to run a process
• 1. Foreground Process
• 2. Background Process
Foreground Process
• Every process when started runs in foreground by default,
receives input from the keyboard, and sends output to the
screen.
• Eg: ls, pwd,
• When a command/process is running in the foreground, no other
processes can be run or started because the prompt would not be
available until the program finishes processing and comes out.
Background Process
• A background process is a process that is started from a
shell (or terminal) and then runs independently.
• When a background process has been launched from a
terminal session, the same terminal will be immediately
available to execute other commands.
Ps (Process Status)
• It is used to view currently running processes on the system.
• It helps us to determine which process is doing what in our
system, how much memory it is using, how much CPU space
it occupies, user ID, command name, etc .
• The ps command may display different results for different
system.
Synatx : $ps [options]
Eg :
PID - The process ID of running command
TTY - The type of terminal where current command is running
TIME - Tells how much time is used by CPU to run the process
CMD - It is current command
session leader
• All processes within a session share the same SID, which is
the same as the PID of the process that is called setsid(),
also known as the session leader.
• A session leader is any process with a PID that matches its
SID, i,e - session id == process id.
Pstree
• It shows the running processes as a tree.
• The root of the tree is either init or the process with the given
pid.
Synatx : $pstree [options] [option]
Eg:
• To view process tree
cmd $pstree
kill
• It is used to terminate processes manually.
• kill command sends a signal to a process which terminates
the process. If the user doesn’t specify any signal which is to
be sent along with kill command then default TERM signal is
sent that terminates the process.
• The most widely applied signals are as follows:
HUP (1)- It reloads a process.
KILL (9)- It kills a process.
TERM (15)- It stops a process gracefully.
Killall
• The killall is used for killing any running process on the
system based on a given name.
• This command will terminate the processes forcibly when a
specified name matches.
• It can kill a bunch of processes altogether.
• It will first send a signal to every running daemon. If you do
not specify any signal name, by default, it sends the
SIGTERM.
• To define signal name- using the number (example -1) or
via options (example: -s).
Eg :
• The JobID can be a process ID (PID) number, or you can use one of
the following symbol combinations:
%Number : Use the job number such as %1 or %2.
%String : Use the string whose name begins with suspended
command such as %commandNameHere or %ping.
%+ OR %% : Refers to the current job.
%- : Refers to the previous job
Eg :
Eg :bg process
• The JobID can be a process ID (PID) number, or you can use one of
the following symbol combinations:
• %Number : Use the job number such as %1 or %2.
• %String : Use the string whose name begins with suspended
command such as %commandNameHere or %ping.
• %+ OR %% : Refers to the current job.
• %- : Refers to the previous job.