Computer System Concepts
Computer System Concepts CS 350
Popular in Course
Popular in ComputerScienence
verified elite notetaker
This 3 page Class Notes was uploaded by Abe Jones on Saturday September 12, 2015. The Class Notes belongs to CS 350 at West Virginia University taught by Bojan Cukic in Fall. Since its upload, it has received 9 views. For similar materials see /class/202751/cs-350-west-virginia-university in ComputerScienence at West Virginia University.
Reviews for Computer System Concepts
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/12/15
include ltstdiohgt include ltsystypeshgt include ltunistdhgt int main int x x0 fork x1 printf 1 am 1d xd n 10nggetpid x return 0 Program output 1 am 21041 x1 1 am 21040 x1 include ltstdiohgt include ltsystypeshgt include ltunistdhgt int main pidit Childipid childipidfork if childipi 1 printfquotFailed to forknquot return 1 if childipid Chi1d code printfquot1 am the Child pidldnquot10nggetpid else printfquot1 am the parent pidldnquot10nggetpid return 0 Program output 1 am the Child pid21099 1 am the parent pid21098 How to synchronize parentchild execution include ltstdiohgt include ltsystypes hgt include ltunistdhgt int main pidit childipid int i childipidfork if child pidltO printhquotFailed to forknquot exit l if childipid child code for iO ilt5 i printfquotid else parent code waitNULL for i5 iltlO i printfquotid pidldnquotilonggetpid pidldnquotilonggetpid child amp parent printfquotProcess ld parent ld nquotlonggetpidlonggetppid return 0 Program output 10 pid2l266 Process 21265 21266 21266 21266 21266 1266 21265 21265 21265 21265 parent 21265 parent 20976 Creating include include include int mainint argc a Chain of processes ltstdiohgt ltsystypeshgt ltunistdhgt char argv pidit childipid0 int i n if argcl2 fprintfstderrquotUsage return 1 s processesnquotargv0 natoiargv1 for iO iltn i if childipidfork break 1d parent 1D1d nquot longgetppid printfquoti d processID i longgetpid return 0 Program output fittlhomeCukiCcs350fork aout 3 i 3 processID 21512 parent 1D21511 i 2 processID 21511 parent 1D21510 i 1 processID 21510 parent 1D221509 i O processID 21509 parent 1D220976 mn atoiargv1 for iO iltn i if childipidforklt0 break 1d parent 1D1d nquot printfquoti d processID 39 longgetppid 1 longgetpid return 0 Program out ut fittlhomeCukiCcs350fork aout 3 i O processID 21546 parent 1D21545 i 1 processID 21547 parent 1D21545 i 2 processID 21548 parent 1D21545 1 3 processID 21545 parent 1D220976
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'