unix process states
TRANSCRIPT
-
7/25/2019 Unix process states
1/7
Understanding Linux Process StatesAuthor: Yogesh BabarTechnical Reviewer: Chris NegusEditor: Allison Pranger08/!/"0!"
OVERVIEW
Aprocessis an instance o# a co$%uter %rogra$ that is currentl& being e'ecuted( Associated with a %rocess
is a variet& o# attributes )ownershi%* nice value* and +E,inu' conte't* to na$e a #ew- that e'tend or li$it its
abilit& to access resources on the co$%uter( .uring the li#e o# a %rocess* it can go through di##erent states(
To get started with the various states o# a %rocess* co$%are a ,inu' %rocess to a hu$an being( Ever&
hu$an being has di##erent stages o# li#e( The li#e c&cle begins with the %arents giving birth to an o##s%ring)s&non&$ous to a %rocess being forkedb& its %arent %rocess-(
A#ter birth* hu$ans start living their lives in their surroundings and start using available resources #or their
survival )s&non&$ous to a %rocess being in a Runningstate-( At so$e %oint in the li#e c&cle* hu$ans need to
wait #or so$ething that the& $ust have be#ore the& can continue to the ne't ste% in their lives )this is
s&non&$ous to a %rocess being in the Sleepstate-( And ust as ever& hu$an li#e $ust co$e to an end*
ever& %rocess $ust also die at so$e %oint in ti$e(
This tech brie# will hel% &ou understand the di##erent states in which a %rocess can be(
UNDERSTANDING PROCESS TYPES
There are di##erent t&%es o# %rocesses in a ,inu' s&ste$( These t&%es include user %rocesses* dae$on
%rocesses* and ernel %rocesses(
User Processes
1ost %rocesses in the s&ste$ are user %rocesses( A user %rocess is one that is initiated b& a regular user
account and runs in user s%ace( 2nless it is run in a wa& that gives the %rocess s%ecial %er$issions* an
ordinar& user %rocess has no s%ecial access to the %rocessor or to #iles on the s&ste$ that don3t belong to
the user who launched the %rocess(
Daeon Process
A dae$on %rocess is an a%%lication that is designed to run in the bacground* t&%icall& $anaging so$e ind
o# ongoing service( A dae$on %rocess $ight listen #or an inco$ing re4uest #or access to a service( 5or
e'a$%le* the httpddae$on listens #or re4uests to view web %ages( 6r a dae$on $ight be intended toinitiate activities itsel# over ti$e( 5or e'a$%le* the cronddae$on is designed to launch cron obs at %reset
ti$es(
Although dae$on %rocesses are t&%icall& $anaged as services b& the root user* dae$on %rocesses o#ten
run as non7root users b& a user account that is dedicated to the service( B& running dae$ons under di##erent
user accounts* a s&ste$ is better %rotected in the event o# an attac( 5or e'a$%le* i# an attacer were to
tae over the httpddae$on )web server-* which runs as the A%ache user* it would give the attacer no
Understanding Linux Process States | Yogesh Babar 1
-
7/25/2019 Unix process states
2/7
s%ecial access to #iles owned b& other users )including root- or other dae$on %rocesses(+&ste$s o#ten start dae$ons at boot ti$e and have the$ run continuousl& until the s&ste$ is shut down(
.ae$ons can also be started or sto%%ed on de$and* set to run at %articular s&ste$ run levels* and* in so$e
cases* signaled to reload con#iguration in#or$ation on the #l&(
!erne" Processes
ernel %rocesses e'ecute onl& in ernel s%ace( The& are si$ilar to dae$on %rocesses( The %ri$ar&
di##erence is that ernel %rocesses have #ull access to ernel data structures* which $aes the$ $ore
%ower#ul than dae$on %rocesses that run in user s%ace(
ernel %rocesses also are not as #le'ible as dae$on %rocesses( You can change the behavior o# a dae$on
%rocess b& changing con#iguration #iles and reloading the service( Changing ernel %rocesses* however*
$a& re4uire reco$%iling the ernel(
INTRODUCING SYSTE# STATES
9hen a %rocess is created* the s&ste$ assigns it a state( The state #ield o# the %rocess descri%tor describes
the current state o# the %rocess( The value o# the state #ield is usuall& set with a si$%le assign$ent* as
shown in this e'a$%le:
p->state = TASK_RUNNING
ere* pstands #or Process* stateis the #lag* and TASK_RUNNINGindicates that %rocess is currentl&
running or read& to run(
1ost %rocesses are in one o# the #ollowing two states:
A %rocess that is on the CP2 )a running %rocess-
A %rocess that is o## the CP2 )a not7running %rocess-
6nl& one %rocess can run at a ti$e on a single CP2( All other %rocesses have to wait or be in so$e other
state( This is wh& a %rocess that is not running a%%ears in a di##erent state( +tates include the #ollowing:
Runnable state
+lee%ing state
2ninterru%table slee% state
.e#unct or ;o$bie state
-
7/25/2019 Unix process states
3/7
$igure %& Processes t'roug' di((erent states )et*een )irt' and terination
Starting a Process +,orn or $or-ed.As %er the fork(2)$an %age* forkcreates a new %rocess b& du%licating the calling %rocess( The new
%rocess* re#erred to as the child* is an e'act du%licate o# the calling %rocess )re#erred to as the %arent-*
e'ce%t #or the #ollowing %oints:
The child has a uni4ue %rocess
-
7/25/2019 Unix process states
4/7
Running StateThe $ost %recious resource in the s&ste$ is the CP2( The %rocess that is e'ecuting and using the CP2 at a
%articular $o$ent is called a running%rocess( You can run the psand topco$$ands to see the state o#
each %rocess( th #ield in the "proc""stat#ile )where re%resents the %rocess
-
7/25/2019 Unix process states
5/7
top 2*2+*25 up 2*5, users, load average* %3+, 3%-, 3%$asks* . total, 2 running, .2 sleeping, / stopped, / 0ombie!pu(s)* %&'$#s, '*$s+, /%/1ni, %1id, /%/1wa, /%1hi, /%1si, /%/1st
Runna)"e State
9hen a %rocess is in a Runnable state* it $eans it has all the resources it needs to run* e'ce%t that the CP2
is not available( The Runnable state o# this %rocess is shown as R in psout%ut(
Consider a e'a$%le( A %rocess is dealing with
-
7/25/2019 Unix process states
6/7
is bus& with so$e other %rocess(
-
7/25/2019 Unix process states
7/7
SU##ARY5ro$ the ti$e a %rocess is born to when it is ter$inated* the %rocess %roceeds through various states(
Those states can include Runnable* Running* +lee%ing )in $e$or& and on dis-* and ;o$bie states( The
out%ut o# the ps ,elco$$and lets &ou see the various states associated with each %rocess on &our
s&ste$(
Understanding Linux Process States | Yogesh Babar 7
Co%&right G "0!" Red at*