7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
1/24
Operating
SystemsLecture 12
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
2/24
January 27, 2016 Copyright Virtual University of Paistan
Agenda for Today
!evie" of previous lectureProcess #anage#ent co##an$s%
bg, fg, ^Z, jobs, ^C, kill&hrea$ concept
Pros an$ cons of threa$s
User an$ ernel threa$s
Pthrea$s li'rary "ith e(a#ple
!ecap of lecture
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
3/24
January 27, 2016 Copyright Virtual University of Paistan
Review of Lecture 11
Use of )*)+s in a progra#a#ple co$e
Process #anage#ent inU-*./Linu(
U-*./Linu( co##an$s/calls%mknod, mkfifo, ps, top
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
4/24
January 27, 2016 Copyright Virtual University of Paistan
The fgCommand
fg [%job_id]
fgresu#es the e(ecution of a
suspen$e$ o' in the foregroun$an$ #oves a 'acgroun$ o'
into the foregroun$ *f %job_id is o#itte$ the
current o' is assu#e$
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
5/24
January 27, 2016 Copyright Virtual University of Paistan
The bgcommand
bg [ %job_id]bgresu#es the e(ecution of a
suspen$e$ o' in the'acgroun$
*f o'3i$ is o#itte$ the currento' is assu#e$ bgruns the current or specifie$
o's in the 'acgroun$
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
6/24
January 27, 2016 Copyright Virtual University of Paistan
The jobscommand
jobs
jobs$isplays status of
suspen$e$ an$ 'acgroun$processes
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
7/24
January 27, 2016 Copyright Virtual University of Paistan
Suspending a Processsen$s a &+P/UP4-5signal to the current process &heshell $isplays a #essage saying that
the o' has 'een suspen$e$ an$$isplays its pro#pt
ou can then #anipulate the state ofthis o', put it in the 'acgroun$ "iththe bgco##an$, run so#e otherco##an$s, an$ then eventually 'ringthe o' 'ac into the foregroun$ "ith
the fgco##an$
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
8/24
January 27, 2016 Copyright Virtual University of Paistan
$ find / -name foo -print 2> /dev/null^Z
[1]+ Stopped find -n!me foo -print "> de#nll
$bg
[1]+ find -n!me foo -print "> de#nll
$ jobs
[1]+ &nning find -n!me foo -print "> de#nll
$ fg
find -n!me foo -print "> de#nll
[ 'omm!nd otpt ]
$
Sample Session
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
9/24
January 27, 2016 Copyright Virtual University of Paistan
Terminating Current
Processsen$s the **-&
signal to the current process,"hich, 'y $efault, ter#inates
the process$ find / -name foo -print 1> out 2> /dev/null
^C
$
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
10/24
January 27, 2016 Copyright Virtual University of Paistan
Terminating a Process
kill [-sign!l] ()*sen$ssignal nu#'er 8signal9 to process
"ith *5 8P*59kill 1"sen$s the *&4!:
signal to the process "ith *5 12;kill ,sen$s the 8sure ill9
signal, eg, kill , ./"/
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
11/24
January 27, 2016 Copyright Virtual University of Paistan
Terminating a Process
kill ,l$isplays the signalssupporte$ 'y the syste# an$
their nu#'ers$ kill -l10 S)23( "0 S))45 0 S)63)5 /0 S))77
80 S)5&9( :0 S)9;&5 0 S)=5 ?0 S)@(=
0 S)A)77 1.0 S);3S 110 S)S=B 1"0 S)SS
10 S)()(= 1/0 S)97& 180 S)5=& 1:0 S)3S&1
DDD
$
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
12/24
January 27, 2016 Copyright Virtual University of Paistan
Issues with Processes
&he foruire$ to pass
infor#ation 'et"een a parent
an$ its chil$ processes
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
13/24
January 27, 2016 Copyright Virtual University of Paistan
Thread Concept
? threa$ is a @light"eightA process"hich e(ecutes "ithin the a$$ressspace of a process
? threa$ can 'e sche$ule$ to run
on a CPU as an in$epen$ent unit
an$ ter#inate
:ultiple threa$s can run
si#ultaneously
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
14/24
January 27, 2016 Copyright Virtual University of Paistan
Thread Concept
&hrea$s have their o"n&hrea$ *5
CPU conte(t
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
15/24
January 27, 2016 Copyright Virtual University of Paistan
Thread Concept
&hrea$s shareCo$e an$ $ata
+pen files
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
16/24
January 27, 2016 Copyright Virtual University of Paistan
Single andultithreaded
Processes
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
17/24
January 27, 2016 Copyright Virtual University of Paistan
Threads are Similar to
Processes? threa$ can 'e in states si#ilar
to a process
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
18/24
January 27, 2016 Copyright Virtual University of Paistan
Threads are !ifferent
from Processes:ultiple threa$s can operate
"ithin the sa#e a$$ress space-o @auto#aticA protection
#echanis# is in place forthrea$sthey are #eant to help
each other
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
19/24
January 27, 2016 Copyright Virtual University of Paistan
Advantages of Threads
Responsiveness
:ultiDthrea$e$ servers
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
20/24
January 27, 2016 Copyright Virtual University of Paistan
Advantages of Threads
!esource sharing
Process resources
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
21/24
January 27, 2016 Copyright Virtual University of Paistan
Advantages of Threads
Economy&ae less ti#e to create,
sche$ule, an$ ter#inateolaris 2% threa$ creation is ;0
ti#es faster than process
creation an$ threa$ s"itching is
five ti#es faster than process
s"itching
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
22/24
January 27, 2016 Copyright Virtual University of Paistan
Advantages of Threads
Performancein #ultiDprocessor
an$ #ultiDthrea$e$ architectures
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
23/24
January 27, 2016 Copyright Virtual University of Paistan
!isadvantages of
Threads!esource sharing
synchroniGation nee$e$'et"een threa$s
5ifficult to "rite an$ $e'ug#ultiDthrea$e$ progra#s
7/25/2019 Operating Systems - CS604 Power Point Slides Lecture 12
24/24
January 27, 2016 Copyright Virtual Universit f P i t
Recap of Lecture
User an$ ernel threa$sPthrea$s
a#ple co$eU-*./Linu( co##an$s/calls%
ptEre!d_'re!te,ptEre!d_join,
ptEre!d eFit
Top Related