class17 ppt Exceptions Topics 15 213 class17 ppt current next exception event 2 optional exception OS Exceptions simultaneously class17 ppt 3 class17 ppt 4 Processes Concurrently er class17 ppt execve execl waitpid fork exit wait 5 printf L0 n printf L2 n fork class17 ppt printf Bye n printf L1 6 L0 L1 L2 Bye Bye Bye Bye printf L0 n printf L2 n fork class17 ppt printf Bye n printf L1 7 L0 Bye L1 Bye L2 Bye Bye n n G Z G XY Z W XY J N K W U c LM S V T G N EO EF LM C EF B CD A B E A A JK S S EO S A S Y F I Q JK Ea b Q N M N 8 PQ K G printf HF S UQ BR J V ps S X getpid T N printf U getpid exit 0 S I BQ 6 Q 1 5 3 4 1 2 1 2 0 0 0 0 0 0 0 0 0 0 0 0 9 9 ps linux 8 8 7 ps linux linux class17 ppt linux Zombie Example 3 4 ps tcsh tcsh ps n n G Z XY G W Z U J XY S BQ K c T W X V N S K G G EF LM C EF B C A B E A A JK printf EO N S S A BR S PQ Y F JK Ea Q EO b I N M Q 9 S J HF T S U ps I UQ printf V S getpid LM getpid exit 0 N N Q tcsh ps ps 3 4 tcsh 1 2 0 0 0 0 0 0 0 0 0 0 ps linux linux linux ps 3 class17 ppt linux Nonterminating Child Example argv argv 54 5 6 6 sort command 4 6 6 2 6 6 3 6 10 6 4 5 complete cnt 5 5 int main stdlib h stdio h unistd h argc Steps Task class17 ppt argv i getpid 5 4 argv 2 4 6 4 3 4 6 1 3 3 1 2 2 6 1 1 1 2 int invoke int i 2 2 1 6 5 4 2 argc 4 4 2 2 2 2 2 argv perror sort exit 1 execl 2 4 6 fork 4 4 printf execl argv 2 class17 ppt 11 argc 1 1 wpid n 4 4 4 2 4 4 12 6 4 2 4 6 4 6 6 2 5 int 2 6 pid 6 1 6 2 1 2 2 wait wpid 4 printf 6 4 else printf cnt 4 class17 ppt 4 4 wpid 6 4 Num 2 9 11 14 17 Name SIGINT SIGKILL SIGSEGV SIGALRM SIGCHLD class17 ppt Signals Terminate Ignore Default Terminate Terminate 13 Description Signals cntl c ved 1 2 tcsh ps ps 3 4 tcsh 0 0 0 0 0 0 0 4 0 0 0 3 ps pid 14 linux linux linux linux ps class17 ppt kill pid kill SIGKILL kill Program n wpid U W T b U S F U T T Q F G JK N EO A H E wpid LM P EO LM EO b Z G N G b W N b H Y U Y E G E A B B A A A B A class17 ppt E E printf E N else b LM M wpid T S printf kill pid while 1 N pid pid N pid int i int child status B W V N U Y b E Y G E printf S M c A U I Y UQ F A BR P UQ U pid B b Ca BR B Y EF FP S S P T N b I H S F EF F T P C UQ F E UQ UQ M U U T N F U S b G F UM G BR S U O HF N T T Q I c N U W K 15 pid i J O F 2 6 4 4 6 2 3 1 2 2 4 6 16 int handler 4 4 class17 ppt pid N pid int 4 sig printf exit 0 int handler signal sig Function getpid sig handler 4 occurred W J O K S B 17 Q N T B I c VS b b B F B G A G T U N U J V S F TS N T M VS N Q K EF C F U B N S M b A N cQ W G M U Ca U N B M b H E E G Y E N T JK JK E A W LM E b EF Q T c Q A VS B N A M L G U S M EF EO N b N Q TS S Q b U G N W Z pid pid N int ccount Q U Q T HF B G T U E H M exit 0 int child status pid pid ccount printf sig pid E S b U ccount pid U class17 ppt U HF R F Signals pid W sig W O S I Q B HF 18 c R B F A F b U F B T Q N T N VS TS V N M M U E N Q U M int child status pid pid pid ccount printf S T E Q B EO N TS L Y E M EF E E Ca N T U N W Z Q G Q B Q VS N M class17 ppt A M wait U c 2 ctl 6 2 4 4 19 6 4 6 4 3 stdlib stdio 2 54 6 6 6 printf 2 6 5 5 4 4 4 4 class17 ppt printf OK printf fflush stdout 4 2 6 4 4 2 4 4 4 4 4 20 4 stdio 54 5 4 int 6 6 printf BEEP fflush stdout 5 4 1 4 printf BOOM class17 ppt 2 class17 ppt longjmp jmp buf j Implementation Nonlocal 21 jmp buf longjmp setjmp longjmp eax class17 ppt setjmp setjmp Implementation meaning longjmp jmp buf setjmp 22 int i cont buf n setjmp longjmp example 2 n 2 4 6 2 6 23 2 setjmp h 1 1 6 3 6 6 2 2 1 1 5 jmp 6 class17 ppt longjmp buf setjmp buf printf else printf 6 5 6 4 1 4 3 4 5 6 54 6 6 2 1 5 1 4 4 4 2 4 1 4 24 starting processing processing restarting processing processing processing restarting processing restarting processing processing class17 ppt printf restarting sigsetjmp buf printf starting Ctrl c Ctrl c Ctrl c printf processing siglongjmp buf setjmp sigjmp stdio c d 1 4 P2 P2 2 1 setjmp env P1 jmp 2 P3 longjmp env class17 ppt 25 env longjmp P3 P2 P2 P2 P1 longjmp P1 1 setjmp env 1 2 P3 longjmp env P2 P1 jmp class17 ppt 26 env X env P2 P1 setjmp P2 P1 env …
View Full Document