!"#$%&'()*+,'(-.'*+/*' ()*5+)(6+7'(*'#)*+89:%5 !,/+!"35-5+)-+;**+<$=$*5+'>+)+2?5-$:

Size: px
Start display at page:

Download "!"#$%&'()*+,'(-.'*+/*' ()*5+)(6+7'(*'#)*+89:%5 !,/+!"35-5+)-+;**+<$=$*5+'>+)+2?5-$:"

Transcription

1 !"#$%&'()*+,'(-.'*+/*' ()*5+)(6+7'(*'#)*+89:%5!"#$%&'()*+,-./01-*(+-(!-23/+4,("56+426!"#$%&'$(%)( 7,8(9:-2;6(!8(<,466-/. 234()*5 C4,*4A(6-B>;,4 7'(*'#)*+B9:%5 D33AE0;1-*(0-.4 *%+,-(&#./ 0(1 2

2 CA$+D'.*6+'>+E9*&-)5F3(4 "+;+4(E*0A/.46(242-,5(E2;?4(F(,4?E6+4,(G;A/46(F(3,-?,;2(0-/*+4, G$49*).*?+503-#A$5+>.':+'($+%.'#$55+-'+)('-A$. "/634*.(3,-0466(>:4*(E+(*44.6()HI(,46-/,04(-,(124,(4G4*+(-00/,6 J46/24(3,-0466(>:4*()HI(;G;EA;KA4(-,(?EG4*(60:4./AE*?(3,E-,E+5 ;%%$).5+-'+95$.H5I+)5+3>+)**+%.'#$55$5+$"$#9&(4+53:9*-)($'95*? LG4*(+:-/?:(2-6+( (0;*(-*A5(4M40/+4(-*4(3,-0466(;+(;(124 LM043+(3-66EKA5(>E+:(A->4,(34,N-,2;*04(+:;*(EN(,/**E*?(;A-*4 K)53#+>9(#&'(5 fork263;>*6(*4>(3,-0466!;aa4.(-*04o(,4+/,*6(+>e04 exit2+4,2e*;+46(->*(3,-0466!;aa4.(-*04o(*4g4,(,4+/,*6 P/+6(E+(E*+-(QR-2KE4S(6+;+/6 wait22;*.(waitpid2>;e+(n-,(;*.(,4;3(+4,2e*;+4.(0:ea.,4* V*.4,6+;*.E*?(+:4(*-*6+;*.;,.(642;*106(-N(+:4(N/*01-*6 DG-E.E*?(E23,-34,(/64(-N(656+42(,46-/,046 L8?8(QW-,@(K-2K6S(0;*(.E6;KA4(;(

3 [0] init [1] Daemon e.g. httpd Login shell Child Child Child Grandchild Grandchild 5 2A$**+@.'4.):5 ;+!"#$$+35+)(+)%%*3#)&'(+%.'4.):+-A)-+.9(5+%.'4.):5+'(+N$A)*>+ '>+-A$+95$.O sh++ P.343()*+L(3"+5A$**+H2-$%A$(+K'9.($Q+;CRC+K$**+<)N5Q+STUUI csh K2V+L(3"+,+5A$**+Htcsh: $(A)(#$6+csh+)-+,EL+)(6+$*5$0A$.$)+ bash K'9.($W;4)3(X+2A$** int main() { char cmdline[maxline];!"#$%&'()*+),)+#-%#($#)'.) /#,01#2,3%,4#)+4#5+ while (1) { /* read */ printf("> "); Fgets(cmdline, MAXLINE, stdin); if (feof(stdin)) exit(0); /* evaluate */ eval(cmdline); 6

4 23:%*$+2A$**+eval+/9(#&'( void eval(char *cmdline) { char *argv[maxargs]; /* argv for execve() */ int bg; /* should the job run in bg or fg? */ pid_t pid; /* process id */ bg = parseline(cmdline, argv); if (!builtin_command(argv)) { if ((pid = Fork()) == 0) { /* child runs user job */ if (execve(argv[0], argv, environ) < 0) { printf("%s: Command not found.\n", argv[0]); exit(0); if (!bg) { /* parent waits for fg job to terminate */ int status; if (waitpid(pid, &status, 0) < 0) unix_error("waitfg: waitpid error"); else /* otherwise, don t wait for bg job */ printf("%d %s", pid, cmdline); 7 DA)-+Y5+)+ZK)#F4.'9(6+8'NX[ L5$.5+4$($.)**?+.9(+'($+#'::)(6+)-+)+&:$ 9534(0-22;*.O(,4;.(-/+3/+O(+534(;*-+:4,(0-22;*. 2':$+%.'4.):5+.9(+Z>'.+)+*'(4+&:$X LM;23A4'(Q.4A4+4(+:E6(XA4(E*(+>-(:-/,6S unix> sleep 7200; rm /tmp/junk # shell stuck for 2 hours ;+ZN)#F4.'9(6X+B'N+35+)+%.'#$55+0$+6'(\-+0)(-+-'+0)3-+>'. unix> (sleep 7200 ; rm /tmp/junk) & [1] 907 unix> # ready for next command 8

5 @.'N*$:+03-A+23:%*$+2A$**+!"):%*$ P9.+$"):%*$+5A$**+#'..$#-*?+0)3-5+>'.+)(6+.$)%5+>'.$4.'9(6+B'N5 K9-+0A)-+)N'9-+N)#F4.'9(6+B'N5[ YEAA(K40-24(R-2KE46(>:4*(+:45(+4,2E*;+4 YEAA(*4G4,(K4(,4;34.(K40;/64(6:4AA(T+53E0;AA5U(>EAA(*-+(+4,2E*;+4 Z-.4,*(V*EM'(-*04(5-/(4M044.(5-/,(3,-0466([/-+;O(5-/,(6:4AA(0;*\+(,/*(;*5( unix> limit maxproc maxproc unix> ulimit -u # csh syntax # bash syntax 9:4(6:4AA(.-46*\+(@*->(>:4*(;(K;0@?,-/*.(]-K(>EAA(X*E6: <5(*;+/,4O(E+(0-/A.(:;334*(;+(;*5(124 9:4(6:4AA\6(,4?/A;,(0-*+,-A(^->(0;*\+(,4;3(4ME+4.(K;0@?,-/*.(3, (E*(;( 124A5(N;6:E-* J4?/A;,(0-*+,-A(^->(E6(Q>;E+(/*1A(,/**E*?(]-K(0-23A4+46O(+:4*(,4;3(E+S 2'*9&'(1+!"#$%&'()*+#'(-.'*+^'0 9:4(@4,*4A(>EAA(E*+4,,/3+(,4?/A;,(3,-0466E*?(+-(;A4,+(/6(>:4*(;(K;0@?,-/*.( 3,-0466(0-23A4+46 )*(V*EMO(+:4(;A4,+(240:;*E62(E6(0;AA4.(;(+*6(,3 10

6 234()*5 ;+!%&'($+35+)+5:)**+:$55)4$+-A)-+('&_$5+)+%.'#$55+-A)-+)(+$=$(-+ '>+5':$+-?%$+A)5+'##9..$6+3(+-A$+5?5-$: 3, E?*;A(+534(E6(E.4*1X4.(K5(62;AA(E*+4?4,()7_6(T&#`aU -*A5(E*N-,2;1-*(E*(;(6E?*;A(E6(E+6()7(;*.(+:4(N;0+(+:;+(E+(;,,EG ,:# 8#.,%34);$&'( <'//#+5'(0*(6)!2#(4 ` 2YaY7C C$.:3()-$ Y(-$..9%-+H$O4OQ+#-*W#+>.':+F$?N').6I T 2YabY<< C$.:3()-$ b3**+%.'4.):+h#)(('-+'=$..36$+'.+34('.$i SS 2Ya2!ac C$.:3()-$+R+V9:% 2$4:$(-)&'(+=3'*)&'( Sd 2Ya;<GE C$.:3()-$ C3:$.+534()* SU 2Ya,M<V Y4('.$,A3*6+5-'%%$6+'.+-$.:3()-$6 11 2$(63(4+)+234()* b$.($*+!#')!+h6$*3=$.5i+)+534()*+-'+)+)#!*'(*+',-.+/#!!+n?+ 9%6)&(4+5':$+5-)-$+3(+-A$+#'(-$"-+'>+-A$+6$5&()&'(+%.'#$55 b$.($*+5$(65+)+534()*+>'.+'($+'>+-a$+>'**'03(4+.$)5'(51 C4,*4A(:;6( (;(656+42(4G4*+(6/0:(;6(.EGE.4#K5#R4,-(T")bWPLU(-,(+:4( +4,2E*;1-*(-N(;(0:EA.(3,-0466(T")b!=c7U 12

7 G$#$3=3(4+)+234()* ;+6$5&()&'(+%.'#$55+.#/#%0#!+)+534()*+0A$( >'.#$6+N?+-A$+ F$.($*+-'+.$)#-+3(+5':$+0)?+-'+-A$+6$*3=$.?+'>+-A$+534()* CA.$$+%'553N*$+0)?5+-'+.$)#-1 76('/#(+:4(6E?*;A(T.-(*-+:E*?U =#/:*(,4#(+:4(3,-0466(T>E+:(-31-*;A(0-,4(./23U <,4$>,+:4(6E?*;A(K5(4M40/1*?(;(/64,#A4G4A(N/*01-*(0;AA4.(+*6(,3)>,(03#/ ;65*0:,-*-/6(E*+4,,/3+ ;+534()*+35+-#')%'&+3>+5$(-+N9-+('-+?$-+.$#$3=$6 9:4,4(0;*(K4(;+(2-6+(-*4(34*.E*?(6E?*;A(-N(;*5(3;,10/A;,(+534 )23-,+;*+'("E?*;A6(;,4(*-+([/4/4. ;+%.'#$55+#)(+1$+/2+-A$+.$#$3%-+'>+#$.-)3(+534()*5 ;+%$(63(4+534()*+35+.$#$3=$6+)-+:'5-+'(#$ 14

8 15 234()*+,'(#$%-5+ b$.($*+:)3(-)3(5+pending+)(6+blocked+n3-+=$#-'.5+3(+-a$+ #'(-$"-+'>+$)#A+%.'#$55 pending'(,43,464*+6(+:4(64+(-n(34*.e*?(6e?*;a6 /'.$W 4.'9(6 B'N K)#FW 4.'9(6 B'N+eS K)#FW 4.'9(6 B'N+e` 34+..,A3*6,A3*6 pid=10 pgid=10?'/#6/'%(0) 3(/2&.+4') -.+/#!!,&.+4-,56 B,$C6/'%(0 5/'$#++)6/'%5)DA pid=20 pgid=20 pid=32 pgid=32 pid=40 pgid=40 pid=21 pgid=20 pid=22 pgid=20 getpgrp() 5+$&%"26%('+##27%(&62(82'&%%+"$26%('+## setpgid() 94:"7+26%('+##27%(&62(82:26%('+##

9 /bin/kill %.'4.):+ 5$(65+).N3-.).?+534()*+-'+)+ %.'#$55+'.+%.'#$55+4.'9%!"):%*$5 /bin/kill $(6+2YabY<<+-'+%.'#$55+`dgSg /bin/kill $(6+2YabY<<+-'+$=$.?+%.'#$55+3(+ %.'#$55+4.'9%+`dgSU linux>./forks 16 Child1: pid=24818 pgrp=24817 Child2: pid=24819 pgrp=24817 linux> ps PID TTY TIME CMD pts/2 00:00:00 tcsh pts/2 00:00:02 forks pts/2 00:00:02 forks pts/2 00:00:00 ps linux> /bin/kill linux> ps PID TTY TIME CMD pts/2 00:00:00 tcsh pts/2 00:00:00 ps linux> 17 2$(63(4+234()*5+>.':+-A$+b$?N').6 953E*?(0+,A#0(T0+,A#RU(64*.6(;(")b)d9(T")b9"9PU(+-(4G4,5(]-K(E*(+:4(N-,4?,-/*.( 3,-0466(?,-/38 2YaY7C+h+6$>)9*-+)#&'(+35+-'+-$.:3()-$+$)#A+%.'#$55+ 2YaC2C@+h+6$>)9*-+)#&'(+35+-'+5-'%+H595%$(6I+$)#A+%.'#$55 pid=10 pgid= pid=20 pgid=20 /'.$W 4.'9(6 B'N K)#FW 4.'9(6 B'N+eS pid=32 pgid=32 K)#FW 4.'9(6 B'N+e` pid=40 pgid=40,a3*6,a3*6 3(/2&.+4') -.+/#!!,&.+4-,56 B,$C6/'%(0 5/'$#++)6/'%5)DA pid=21 pgid=20?'/#6/'%(0) 5/'$#++)6/'%5)@A pid=22 pgid=20 18

10 !"):%*$+'>+ctrl-c+)(6+ctrl-z 219k>./forks 17 Child: pid=28108 pgrp=28107 Parent: pid=28107 pgrp=28107 <types ctrl-z> Suspended 219k> ps w PID TTY STAT TIME COMMAND pts/8 Ss 0:00 -tcsh pts/8 T 0:01./forks pts/8 T 0:01./forks pts/8 R+ 0:00 ps w 219k> fg./forks 17 <types ctrl-c> 219k> ps w PID TTY STAT TIME COMMAND pts/8 Ss 0:00 -tcsh pts/8 R+ 0:00 ps w 2C;C+H%.'#$55+5-)-$I+<$4$(61 7%.!8,$#9#.: 21+5*$$%3(4 C1+5-'%%$6 G1+.9((3(4 ;#/+'),$#9#.: 51+5$553'(+*$)6$. i1+>'.$4.'9(6+%.'#+4.'9% 2$$+Z:)(+%5X+>'.+:'.$+ 6$-)3*5 19 2$(63(4+234()*5+03-A+kill+/9(#&'( void fork12() { pid_t pid[n]; int i, child_status; for (i = 0; i < N; i++) if ((pid[i] = fork()) == 0) while(1); /* Child infinite loop */ /* Parent terminates the child processes */ for (i = 0; i < N; i++) { printf("killing process %d\n", pid[i]); kill(pid[i], SIGINT); /* Parent reaps terminated children */ for (i = 0; i < N; i++) { pid_t wpid = wait(&child_status); if (WIFEXITED(child_status)) printf("child %d terminated with exit status %d\n", wpid, WEXITSTATUS(child_status)); else printf("child %d terminated abnormally\n", wpid); 20

11 G$#$3=3(4+234()*5 29%%'5$++F$.($*+35+.$-9.(3(4+>.':+)(+$"#$%&'(+A)(6*$.+)( $)6?+-'+%)55+#'(-.'*+-'+%.'#$55+b$.($*+#':%9-$5 pnb = pending & ~blocked 9:4(64+(-N(34*.E*?(*-*KA-0@4.(6E?*;A6(N-,(3,-0466(- Y>++Hpnb == 0I+!*5$ P;66(0-*+,-A(+-(*4M+(E*6+,/01-*(E*(+:4(A-?E0;A(^->(N-,(- J434;+(N-,(;AA(*-*R4,-(2(E*(pnb!:--64(A4;6+(*-*R4,-(KE+(2(E*(pnb ;*.(N-,04(3,-0466(-(+-(/#$#*2#( 6E?*;A(2 9:4(,404E3+(-N(+:4(6E?*;A(+,E??4,6(6-24(,$&'((K5(- P;66(0-*+,-A(+-(*4M+(E*6+,/01-*(E*(A-?E0;A(^->(N-,(- 21 V$>)9*-+;#&'(5!)#A+534()*+-?%$+A)5+)+%.$6$_($6+)#<(4$8,(/*+'Q+0A3#A+35+ '($+'>1 9:4(3,-0466(+4,2E*;+46 9:4(3,-0466(+4,2E*;+46(;*.(./236(0-,4 9:4(3,-0466(6+-36(/*1A(,46+;,+4.(K5(;(")b!Id9(6E?*;A 9:4(3,-0466(E?*-,46(+:4(6E?*;A 22

12 Y(5-)**3(4+234()*+M)(6*$.5 CA$+signal+>9(#&'(+:'63_$5+-A$+6$>)9*-+)#&'(+)55'#3)-$6+03-A+ -A$+.$#$3%-+'>+534()*+signum1 handler_t *signal(int signum, handler_t *handler) V3j$.$(-+=)*9$5+>'.+handler1 ")be)bd'(e?*-,4(6e?*;a6(-n(+534(signum ")be7wc'(,4g4,+(+-(+:4(.4n;/a+(;01-*(-*(,404e3+(-n(6e?*;a6(-n(+534(signum I+:4,>E64O(handler(E6(+:4(;..,466(-N(;(+*6(,3)>,(03#/!;AA4.(>:4*(3,-0466(,404EG46(6E?*;A(-N(+534(signum J4N4,,4.(+-(;6(E*(+4,33*(6F)+:4(:;*.A4, LM40/1*?(:;*.A4,(E6(0;AA4.(E$,4$>*(6F)-,(E>,(03*(6F)+:4(6E?*;A E*6+,/01-*(E*(+:4(0-*+,-A(^->(-N(+:4(3,-0466(+:;+(>;6(E*+4,,/3+4.(K5(,404E3+(-N(+:4(6E?*;A ()*+M)(6*3(4+!"):%*$ void int_handler(int sig) { safe_printf("process %d received signal %d\n", getpid(), sig); exit(0); void fork13() { pid_t pid[n]; int i, child_status; signal(sigint, int_handler); for (i = 0; i < N; i++) if ((pid[i] = fork()) == 0) { Killing process Process received signal 2 while(1); /* child infinite Process loop received signal 2 Process received signal 2 for (i = 0; i < N; i++) { Process received signal 2 printf("killing process %d\n", Process pid[i]); received signal 2 kill(pid[i], SIGINT); for (i = 0; i < N; i++) { pid_t wpid = wait(&child_status); 219k>./forks 13 Killing process Killing process Killing process Killing process Child terminated with exit status 0 Child terminated with exit status 0 Child terminated with exit status 0 Child terminated with exit status 0 if (WIFEXITED(child_status)) Child terminated with exit status 0 printf("child %d terminated 219k> with exit status %d\n", wpid, WEXITSTATUS(child_status)); else printf("child %d terminated abnormally\n", wpid); 24

13 234()*5+M)(6*$.5+)5+,'(#9..$(-+/*'05 ;+534()*+A)(6*$.+35+)+5$%).)-$+*'43#)*+^'0+H('-+%.'#$55I+-A)-+.9(5+#'(#9..$(-*?+03-A+-A$+:)3(+%.'4.):+! Q0-*0/,,4*+A5S(E*(+:4(Q*-+(64[/4*1;AS(64*64( G/'$#++);) while (1) ; G/'$#++); handler(){ G/'$#++)B C3:$ 25 ;('-A$.+c3$0+'>+234()*+M)(6*$.5+)5+,'(#9..$(-+/*'05 =.+/#!!,> =.+/#!!,3 3-7":.2;+.-,+%+; 3-7":.2%+'+-,+; Y #9.. Y ($"- 95$.+#'6$+H:)3(I F$.($*+#'6$ 95$.+#'6$+H:)3(I F$.($*+#'6$ 95$.+#'6$+HA)(6*$.I F$.($*+#'6$ 95$.+#'6$+H:)3(I /+'8#?8,!@%8/" /+'8#?8,!@%8/" 26

14 234()*+M)(6*$.+/9(F3($55 int ccount = 0; void child_handler(int sig) { int child_status; pid_t pid = wait(&child_status); ccount--; safe_printf( "Received signal %d from process %d\n", sig, pid); void fork14() { pid_t pid[n]; int i, child_status; ccount = N; signal(sigchld, child_handler); for (i = 0; i < N; i++) if ((pid[i] = fork()) 219k> == 0)./forks { 14 sleep(1); /* deschedule child */ P4*.E*?(6E?*;A6(;,4(*-+( [/4/4. /'.+$)#A+534()*+-?%$Q+B95-+ A)=$+53(4*$+N3-+3(63#)&(4+ 0A$-A$.+'.+('-+534()*+35+ %$(63(4!=$(+3>+:9*&%*$+%.'#$55$5+ A)=$+5$(-+-A35+534()* Received SIGCHLD signal 17 for process exit(0); /* Child: Received Exit */ SIGCHLD signal 17 for process while (ccount > 0) pause(); /* Suspend until signal occurs */ 27 <3=3(4+D3-A+7'(k9$93(4+234()*5 E95-+#A$#F+>'.+)**+-$.:3()-$6+B'N5 953E0;AA5(A--3(>E+:(wait void child_handler2(int sig) { int child_status; pid_t pid; while ((pid = waitpid(-1, &child_status, WNOHANG)) > 0) { ccount--; safe_printf("received signal %d from process %d\n", sig, pid); void fork15() { k>./forks 15 Received signal 17 from process Received signal 17 from process signal(sigchld, Received child_handler2); signal 17 from process Received signal 17 from process Received signal 17 from process k> 28

15 E'.$+234()*+M)(6*$.+/9(F3($55 234()*+)..3=)*+69.3(4+*'(4+5?5-$:+#)**5+H5)?+)+readI 234()*+A)(6*$.+3(-$..9%-5+read+#)** ce*/m'(/3-*(,4+/,*(n,-2(6e?*;a(:;*.a4,o(+:4(read(0;aa(e6(,46+;,+4.( ;/+-2;10;AA5 "-24(-+:4,(^;G-,6(-N(V*EM(0;*(0;/64(+:4(read 0;AA(+-(N;EA(>E+:(;*( EINTER 4,,-,(*/2K4,(TerrnoU E*(+:E6(0;64O(+:4(;33AE0;1-*(3,-?,;2(0;*(,46+;,+(+:4(6A->(656+42(0;AA 29N-*$+63j$.$(#$5+*3F$+-A$5$+#':%*3#)-$+-A$+0.3&(4+'>+%'.-)N*$+ 29 #include <stdlib.h> #include <stdio.h> #include <signal.h> void handler(int sig) { safe_printf("you think hitting ctrl-c will stop the bomb?\n"); sleep(2); safe_printf("well..."); sleep(1); printf("ok\n"); exit(0); main() { 219k> signal(sigint, handler); /* installs ctl-c handler */ while(1) { $"-$.()*O# 219k>./external <ctrl-c> You think hitting ctrl-c will stop the bomb? Well...OK 30

16 a$($.)-$6+!=$(-5 #include <stdio.h> #include <signal.h> int beeps = 0; /* SIGALRM handler */ void handler(int sig) { safe_printf("beep\n"); if (++beeps < 5) alarm(1); else { safe_printf("boom!\n"); exit(0); 3(-$.()*O# main() { signal(sigalrm, handler); alarm(1); /* send SIGALRM in 1 second */ while (1) { /* handler returns here */ 219k>./internal BEEP BEEP BEEP BEEP BEEP BOOM! 219k> 31 ;5?(#W234()*W2)>$-?+ /9(#&'(+35+(!A'/B!%&'($B!(<#,3>+$3-A$.+.$$(-.)(-+H)**+=).3)N*$5+ 5-'.$6+'(+5-)#F+>.):$Q+,21;@@`$+S`OUO`I+'.+('(W3(-$..9%&N*$+N?+ write(e6(-*(+:4(ae6+o(printf i6(*-+ P($+5'*9&'(1+)5?(#W534()*W5)>$+0.)%%$.+>'.+printf: void safe_printf(const char *format,...) { char buf[maxs]; va_list args; va_start(args, format); /* reentrant */ vsnprintf(buf, sizeof(buf), format, args); /* reentrant */ va_end(args); /* reentrant */ write(1, buf, strlen(buf)); /* async-signal-safe */ 5)>$l%.3(mO# 32

17 V64N/A(N-,(4,,-,(,40-G4,5(;*.(6E?*;A(:;*.AE*? int setjmp(jmp_buf j) Z/6+(K4(0;AA4.(K4N-,4(A-*?]23 ).4*1X46(;(,4+/,*(6E+4(N-,(;(6/K64[/4*+(A-*?]23!;AA4.(-*04O(,4+/,*6(-*4(-,(2-,4(1246 Y:%*$:$(-)&'(1 J4242K4,(>:4,4(5-/(;,4(K5(6+-,E*?((+:4(0/,,4*+(/#6*+4#/)$'(4#"4O(+4,$C) 5'*(4#/O((;*.)G<)2,3%#)E*(jmp_buf J4+/,*(a 33 setjmp/longjmp+h#'(-i void longjmp(jmp_buf j, int i) Z4;*E*?',4+/,*(N,-2(+:4(setjmp(,4242K4,4.(K5(]/23(K/f4,(j(;?;E*(888( g(+:e6(124(,4+/,*e*? i(e*6+4;.(-n(a!;aa4.(;b4,(setjmp!;aa4.(-*04o(k/+(*4g4,(,4+/,*6 longjmp+y:%*$:$(-)&'(1 K/f4,(j "4+(%eax2T+:4(,4+/,*(G;A/4U(+-(i h/23(+-(+:4(a-0;1-*(e*.e0;+4.(k5(+:4(p!(6+-,4.(e*(]/23(k/n(j 34

18 setjmpflongjmp+!"):%*$ #include <setjmp.h> jmp_buf buf; main() { if (setjmp(buf)!= 0) { printf("back in main due to an error\n"); else printf("first time through\n"); p1(); /* p1 calls p2, which calls p3 */... p3() { <error checking code> if (error) longjmp(buf, 1) 35 <3:3-)&'(5+'>+7'(*'#)*+89:%5 D'.F5+03-A3(+5-)#F+635#3%*3($!;*(-*A5(A-*?(]/23(+-(4*GE,-*24*+(-N(N/*01-*(+:;+(:;6(K44*(0;AA4.(K/+( *-+(54+(0-23A4+4. jmp_buf env; P1() { if (setjmp(env)) { /* Long Jump to here */ else { P2(); P2() {... P2();... P3(); P3() { longjmp(env, 1); env <+8(%+2.("7=>6?@+%2.("7=>6 P1 P2 P2 P2 P3 P1 36

19 <3:3-)&'(5+'>+<'(4+89:%5+H#'(-OI D'.F5+03-A3(+5-)#F+635#3%*3($!;*(-*A5(A-*?(]/23(+-(4*GE,-*24*+(-N(N/*01-*(+:;+(:;6(K44*(0;AA4.(K/+( *-+(54+(0-23A4+4. P1 jmp_buf env; P1() { P2(); P3(); env P2?$2#+$=>6 P2() { if (setjmp(env)) { /* Long Jump to here */ P3() { longjmp(env, 1); env A P1 P2 *B2%+$&%"# env A P1 P3?$2.("7=>6 CA)-+G$5-).-5+Y-5$*>+DA$(+ctrl-cJ6 #include <stdio.h> #include <signal.h> #include <setjmp.h> sigjmp_buf buf; void handler(int sig) { siglongjmp(buf, 1); main() { signal(sigint, handler); if (!sigsetjmp(buf, 1)) printf("starting\n"); else printf("restarting\n"); 219k>./restart starting processing... processing... processing... restarting processing... processing... restarting processing... processing... processing... 9$%.C' 9$%.C' while(1) { sleep(1); printf("processing...\n");.$5-).-o# 38

20 29::).? 234()*5+%.'=36$+%.'#$55W*$=$*+$"#$%&'(+A)(6*3(4!;*(?4*4,;+4(N,-2(/64,(3,-?,;26!;*(.4X*4(4f40+(K5(.40A;,E*?(6E?*;A(:;*.A4, 2':$+#)=$)-5 i4,5(:e?:(-g4,:4;. I*A5(/64(N-,(4M0431-*;A(0-*.E1-*6 7-*_+(:;G4([/4/46 h/6+(-*4(ke+(n-,(4;0:(34*.e*?(6e?*;a(+534 7'(*'#)*+B9:%5+%.'=36$+$"#$%&'()*+#'(-.'*+^'0+03-A3(+ %.'#$55 39

Exceptional Control Flow: Signals and Nonlocal Jumps

Exceptional Control Flow: Signals and Nonlocal Jumps Exceptional Control Flow: Signals and Nonlocal Jumps CS-281: Introduction to Computer Systems Instructor: Dr. Thomas C. Bressoud 1 ECF Exists at All Levels of a System Exceptions Hardware and operating

More information

Exceptional Control Flow Part II Nov. 2, 2009"

Exceptional Control Flow Part II Nov. 2, 2009 Exceptional Control Flow Part II Nov. 2, 2009" Unix Startup: Step 2" [0] /etc/inittab Daemons" e.g. ftpd, httpd" init [1] getty init forks and execs daemons per /etc/ inittab, and forks and execs a getty

More information

Exceptional Control Flow Exists at All Levels of a System. Systemprogrammering 2007 Föreläsning 3 Exceptional Control Flow Part II

Exceptional Control Flow Exists at All Levels of a System. Systemprogrammering 2007 Föreläsning 3 Exceptional Control Flow Part II Systemprogrammering 2007 Föreläsning 3 Exceptional Control Flow Part II Topics Process Hierarchy Shells Signals Nonlocal jumps Exceptional Control Flow Exists at All Levels of a System Exceptions Hardware

More information

Exceptional Control Flow Part II

Exceptional Control Flow Part II Exceptional Control Flow Part II William J. Taffe Plymouth State University Using the Slides of Randall E. Bryant Carnegie Mellon University Topics Process Hierarchy Shells Signals Nonlocal jumps ECF Exists

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Exceptional Control Flow Part II Dr. Steve Goddard goddard@cse.unl.edu http://cse.unl.edu/~goddard/courses/csce230j Giving credit where credit is due Most of slides for

More information

Excep&onal Control Flow: Signals and Nonlocal Jumps

Excep&onal Control Flow: Signals and Nonlocal Jumps Excep&onal Control Flow: Signals and Nonlocal Jumps CS- 281: Introduc&on to Computer Systems Instructor: Dr. Thomas C. Bressoud 1 ECF Exists at All Levels of a System Excep&ons Hardware and opera&ng system

More information

ECF Exists at All Levels of a System Exceptional Control Flow Part II Oct. 22, 2002 Topics! Process Hierarchy! Shells! Signals!

ECF Exists at All Levels of a System Exceptional Control Flow Part II Oct. 22, 2002 Topics! Process Hierarchy! Shells! Signals! 15-213 The course that gives CMU its Zip! Exceptional Control Flow Part II Oct. 22, 2002 Topics! Process Hierarchy! Shells! Signals! Nonlocal jumps ECF Exists at All Levels of a System Exceptions! Hardware

More information

Shell and Signals. Computer Organization 3/17/2015. CSC252 - Spring The World of Multiprogramming or Multitasking. Unix Process Hierarchy

Shell and Signals. Computer Organization 3/17/2015. CSC252 - Spring The World of Multiprogramming or Multitasking. Unix Process Hierarchy Shell and Signals Kai Shen The World of Multiprogramming or Multitasking System runs many processes concurrently Process: executing program State includes memory image + register values + program counter

More information

Lecture 24: Multitasking and Signals

Lecture 24: Multitasking and Signals CSCI-UA.0201-003 Computer Systems Organization Lecture 24: Multitasking and Signals Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Some slides adapted (and slightly modified) from: Clark

More information

Processes & Signals. System Runs Many Processes Concurrently. State consists of memory image + register values + program counter

Processes & Signals. System Runs Many Processes Concurrently. State consists of memory image + register values + program counter Processes & Signals Topics Process Hierarchy Shells Signals The World of Multitasking System Runs Many Processes Concurrently Process: executing program State consists of memory image + register values

More information

CS213. Exceptional Control Flow Part II. Topics Process Hierarchy Signals

CS213. Exceptional Control Flow Part II. Topics Process Hierarchy Signals CS213 Exceptional Control Flow Part II Topics Process Hierarchy Signals ECF Exists at All Levels of a System Exceptions Hardware and operating system kernel software Concurrent processes Hardware timer

More information

Mul$tasking and Shells

Mul$tasking and Shells Mul$tasking and Shells CS 485 Systems Programming Fall 2015 Instructor: James Griffioen Adapted from slides by R. Bryant and D. O Hallaron (hip://csapp.cs.cmu.edu/public/instructors.html) 1 Today Mul$tasking,

More information

Program and OS Intera/on: Mul/tasking and Signals

Program and OS Intera/on: Mul/tasking and Signals Program and OS Intera/on: Mul/tasking and Signals Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron 1 Topics Mul/tasking, shells Signals 2 Process Abstrac/on Review Process:

More information

ECF Exists at All Levels of a System

ECF Exists at All Levels of a System Processes & Signals Instructor: Sanjeev Se(a 1 ECF Exists at All Levels of a System Excep@ons Hardware and opera(ng system kernel so6ware Signals Kernel so6ware Non- local jumps Applica(on code Previous

More information

Signals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Signals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Signals Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Multitasking (1) Programmer s model of multitasking fork() spawns new process Called once,

More information

Multitasking. Programmer s model of multitasking. fork() spawns new process. exit() terminates own process

Multitasking. Programmer s model of multitasking. fork() spawns new process. exit() terminates own process Signals Prof. Jin-Soo Kim( jinsookim@skku.edu) TA JinHong Kim( jinhong.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Multitasking Programmer s model of multitasking

More information

Exceptional Control Flow Part II October 24, 2007

Exceptional Control Flow Part II October 24, 2007 15-213 Exceptional Control Flow Part II October 24, 2007 Topics Process Hierarchy Shells Signals Nonlocal jumps class15.ppt ECF Exists at All Levels of a System Exceptions Hardware and operating system

More information

Introduction to Computer Systems , fall th Lecture, Oct. 14 th

Introduction to Computer Systems , fall th Lecture, Oct. 14 th Introduction to Computer Systems 15 213, fall 2009 14 th Lecture, Oct. 14 th Instructors: Majd Sakr and Khaled Harras ECF Exists at All Levels of a System Exceptions Hardware and operating system kernel

More information

Exceptions, Processes and Signals

Exceptions, Processes and Signals Exceptions, Processes and Signals Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3 Shells See https://en.wikipedia.org/wiki/shell_(computing) Instructor: Joanna Klukowska Slides adapted

More information

Programming Assignments will be.. All the PAs are continuous 3 major factors that you should consider

Programming Assignments will be.. All the PAs are continuous 3 major factors that you should consider Signals Prof. Jin-Soo Kim( jinsookim@skku.edu) TA - Dong-Yun Lee (dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu NOTICE Programming Assignments will be.. All

More information

What is an Operating System? Signals, Processes, & Threads. Resource Sharing. Resource Abstraction ... Operating Systems 10/20/2010

What is an Operating System? Signals, Processes, & Threads. Resource Sharing. Resource Abstraction ... Operating Systems 10/20/2010 What is an Operating System? Signals, Processes, & Threads CS 256/456 Dept. of Computer Science, University of Rochester Software that abstracts the computer hardware Hides the messy details of the underlying

More information

Excep&onal Control Flow

Excep&onal Control Flow Excep&onal Control Flow Spring 2012 Instructors: Aykut & Erkut Erdem Acknowledgement: The course slides are adapted from the slides prepared by D.R. O Hallaron, G. Ganger and G. Kesden of Carnegie- Mellon

More information

Excep&onal Control Flow

Excep&onal Control Flow Excep&onal Control Flow Fall 2012 Instructors: Aykut & Erkut Erdem Acknowledgement: The course slides are adapted from the slides prepared by D.R. O Hallaron, G. Ganger and G. Kesden of Carnegie- Mellon

More information

Operating Systems Components. What is an Operating System? Process Management. Memory Management. Operating Systems 9/7/2018 CSC 256/456 1

Operating Systems Components. What is an Operating System? Process Management. Memory Management. Operating Systems 9/7/2018 CSC 256/456 1 What is an Operating System? Operating Systems Components Software that abstracts the computer hardware Hides the messy details of the underlying hardware Presents users with a resource abstraction that

More information

Exceptional Control Flow: Signals and Nonlocal Jumps

Exceptional Control Flow: Signals and Nonlocal Jumps Exceptional Control Flow: Signals and Nonlocal Jumps 15-213: Introduction to Computer Systems 15 th Lecture, June 27, 2018 Instructor: Brian Railing 1 Review from last lecture Exceptions Events that require

More information

Foundations of Computer Systems

Foundations of Computer Systems 18-600 Foundations of Computer Systems Lecture 16: Exceptional Control Flow II: Signals and Nonlocal Jumps John P. Shen & Zhiyi Yu October 24, 2016 18-600 SE PL OS CA Required Reading Assignment: Chapter

More information

Exceptional Control Flow: Signals

Exceptional Control Flow: Signals Exceptional Control Flow: Signals CS 485G-006: Systems Programming Lectures 27 28: 4 6 Apr 2016 1 ECF Exists at All Levels of a System Exceptions Hardware and operating system kernel software Process Context

More information

Last Class. System Calls, Kernel Mode, and Process Implementation. Processes. Today. Operating Systems 9/11/2018 CSC 256/456 1

Last Class. System Calls, Kernel Mode, and Process Implementation. Processes. Today. Operating Systems 9/11/2018 CSC 256/456 1 System Calls, Kernel Mode, and Process Implementation CS 256/456 Dept. of Computer Science, University of Rochester Last Class Processes Process concept Operations on processes Introduction to Signals

More information

CS 201. Processes. Gerson Robboy Portland State University

CS 201. Processes. Gerson Robboy Portland State University CS 201 Processes Gerson Robboy Portland State University Review Definition: A process is an instance of a running program. One of the most fundamental concepts in computer science. Not the same as program

More information

Processes & Threads. (Chapter 3) CS 4410 Operating Systems. [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse]

Processes & Threads. (Chapter 3) CS 4410 Operating Systems. [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse] Processes & Threads (Chapter 3) CS 4410 Operating Systems [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse] Processes! 2 What is a Program? Program is a file containing: executable

More information

Processes: Introduction. CS 241 February 13, 2012

Processes: Introduction. CS 241 February 13, 2012 Processes: Introduction CS 241 February 13, 2012 1 Announcements MP2 due tomorrow Deadline and contest cutoff 11:59 p.m. Fabulous prizes on Wednesday MP3 out Wednesday: Shell (1 week) Code from this lecture

More information

Excep&onal Control Flow: Signals and Nonlocal Jumps

Excep&onal Control Flow: Signals and Nonlocal Jumps Excep&onal Control Flow: Signals and Nonlocal Jumps 15-213: Introduc;on to Computer Systems 15 th Lecture, October 18th, 2016 Instructor: Randy Bryant 1 Review from last lecture Excep&ons Events that require

More information

Operating Systems 9/6/ SIGINT Terminate Interrupt from keyboard (ctl-c) 9 SIGKILL Terminate Kill program (cannot override or ignore)

Operating Systems 9/6/ SIGINT Terminate Interrupt from keyboard (ctl-c) 9 SIGKILL Terminate Kill program (cannot override or ignore) Recap of the Last Class System Calls, Kernel Mode, and Process Implementation CS 256/456 Dept. of Computer Science, University of Rochester Processes Process concept Operations on processes Signals User-level

More information

Exceptional Control Flow Part I

Exceptional Control Flow Part I Exceptional Control Flow Part I Today! Exceptions! Process context switches! Creating and destroying processes Next time! Signals, non-local jumps, Fabián E. Bustamante, 2007 Control flow! Computers do

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 20 LAST TIME: UNIX PROCESS MODEL Began covering the UNIX process model and API Information associated with each process: A PID (process ID) to

More information

Exceptional Control Flow: Exceptions and Processes

Exceptional Control Flow: Exceptions and Processes Exceptional Control Flow: Exceptions and Processes 15-213 / 18-213: Introduction to Computer Systems 12 th Lecture, June 18, 2013 Instructors: Greg Kesden 1 Today Exceptional Control Flow Processes 2 Control

More information

Q & A (1) Where were string literals stored? Virtual Address. SSE2033: System Software Experiment 2 Spring 2016 Jin-Soo Kim

Q & A (1) Where were string literals stored? Virtual Address. SSE2033: System Software Experiment 2 Spring 2016 Jin-Soo Kim Processes Prof. Jin-Soo Kim(jinsookim@skku.edu) TA - Dong-Yun Lee (dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Q & A (1) Where were string literals stored?

More information

Announcement (1) sys.skku.edu is now available

Announcement (1) sys.skku.edu is now available Processes Prof. Jin-Soo Kim( jinsookim@skku.edu) TA JinHong Kim( jinhong.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Announcement (1) sys.skku.edu is now available

More information

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Processes Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Processes An instance of a program in execution. One of the most profound ideas in computer

More information

Today. Exceptional Control Flow Processes. Exceptions and Processes. Control Flow. Altering the Control Flow

Today. Exceptional Control Flow Processes. Exceptions and Processes. Control Flow. Altering the Control Flow Today Exceptional Control Flow: Exceptions and Processes Exceptional Control Flow Processes 15 213 / 18 213: Introduction to Computer Systems 13 th Lecture, Feb 26, 2013 Instructors: Seth Copen Goldstein,

More information

University of Washington What is a process?

University of Washington What is a process? What is a process? What is a program? A processor? A process? 1 What is a process? Why are we learning about processes? Processes are another abstrac'on in our computer system the process abstrac9on provides

More information

Exceptional Control Flow Part I Oct. 28, 2009"

Exceptional Control Flow Part I Oct. 28, 2009 Exceptional Control Flow Part I Oct. 28, 2009" Control Flow" Time" Physical control flow" " inst 1 " inst 2 " inst 3 " " inst n " " 2! 3! Altering the Control Flow" Exceptional Control

More information

Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process?

Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process? Processes and control flow Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process? 1 Control Flow Processors do only one thing:

More information

Exceptional Control Flow Part I September 22, 2008

Exceptional Control Flow Part I September 22, 2008 15-213 Exceptional Control Flow Part I September 22, 2008 Topics Exceptions Process context switches Creating and destroying processes class11.ppt Control Flow Computers do only one thing: From startup

More information

Exceptional Control Flow Part I Oct. 17, 2002

Exceptional Control Flow Part I Oct. 17, 2002 15-213 The course that gives CMU its Zip! Exceptional Control Flow Part I Oct. 17, 2002 Topics Exceptions Process context switches Creating and destroying processes class16.ppt Control Flow Computers do

More information

Today. Introduction to Computer Systems /18 243, Fall th Lecture. Control Flow. Altering the Control Flow.

Today. Introduction to Computer Systems /18 243, Fall th Lecture. Control Flow. Altering the Control Flow. Today Introduction to Computer Systems 15 213/18 243, Fall 2009 11 th Lecture Exceptional Control Flow Processes Instructors: Greg Ganger and Roger Dannenberg Control Flow Processors do only one thing:

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Exceptional Control Flow Part I Dr. Steve Goddard goddard@cse.unl.edu http://cse.unl.edu/~goddard/courses/csce230j Giving credit where credit is due Most of slides for this

More information

Control Flow. Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I. Exceptional Control Flow. Altering the Control Flow

Control Flow. Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I. Exceptional Control Flow. Altering the Control Flow Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I Topics Exceptions Process context switches Creating and destroying processes Control Flow Computers do Only One Thing From startup

More information

Processes, Exceptional

Processes, Exceptional CIS330, Week 9 Processes, Exceptional Control Flow CSAPPe2, Chapter 8 Control Flow Computers do Only One Thing o From startup to shutdown, a CPU simply reads and executes (interprets) a sequence of instructions,

More information

Exceptional Control Flow Part I

Exceptional Control Flow Part I Exceptional Control Flow Part I Today Exceptions Process context switches Creating and destroying processes Next time Signals, non-local jumps, Chris Riesbeck, Fall 2011 Original: Fabian Bustamante Control

More information

System Programming. Signals II

System Programming. Signals II Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Suspending a process 2

More information

Excep&onal Control Flow: Excep&ons and Processes

Excep&onal Control Flow: Excep&ons and Processes Excep&onal Control Flow: Excep&ons and Processes 15-213 / 18-213: Introduc2on to Computer Systems 13 th Lecture, Oct. 11, 2011 Instructors: Dave O Hallaron, Greg Ganger, and Greg Kesden 1 Today Excep&onal

More information

CSCI2467: Systems Programming Concepts

CSCI2467: Systems Programming Concepts CSCI2467: Systems Programming Concepts Slideset 7: Exceptional Control Flow Part 2 Source: CS:APP Chapter 8, Bryant & O Hallaron Instructor: M. Toups Spring 2018 Shell lab Two due dates! Two! updated First

More information

CSC 252: Computer Organization Spring 2018: Lecture 19

CSC 252: Computer Organization Spring 2018: Lecture 19 CSC 252: Computer Organization Spring 2018: Lecture 19 Instructor: Yuhao Zhu Department of Computer Science University of Rochester Action Items: Programming Assignment 3 grades are out Programming Assignment

More information

Excep onal Control Flow: Excep ons and Processes

Excep onal Control Flow: Excep ons and Processes Excep onal Control Flow: Excep ons and Processes 15-213 / 18-213: Introduc on to Computer Systems 13 th Lecture, Oct. 8, 2013 Instructors: Randy Bryant, Dave O Hallaron, and Greg Kesden 1 Today The Process

More information

Processes. CSE 351 Autumn Instructor: Justin Hsia

Processes. CSE 351 Autumn Instructor: Justin Hsia Processes CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/292/

More information

Program and OS interac0ons: Excep0ons and Processes

Program and OS interac0ons: Excep0ons and Processes Program and OS interac0ons: Excep0ons and Processes Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron 1 User- level programs vs. OS safari httpd bomb OS kernel Send/recv packets,

More information

Processes. CSE 351 Autumn Instructor: Justin Hsia

Processes. CSE 351 Autumn Instructor: Justin Hsia Processes CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun https://xkcd.com/627/

More information

Carnegie Mellon. Processes. Lecture 12, May 19 th Alexandre David. Credits to Randy Bryant & Dave O Hallaron from Carnegie Mellon

Carnegie Mellon. Processes. Lecture 12, May 19 th Alexandre David. Credits to Randy Bryant & Dave O Hallaron from Carnegie Mellon Processes Lecture 12, May 19 th 2011. Alexandre David Credits to Randy Bryant & Dave O Hallaron from Carnegie Mellon 1 Processes Defini=on: A process is an instance of a running program. One of the most

More information

Introduction to Computer Systems , fall th Lecture, Oct. 7 th

Introduction to Computer Systems , fall th Lecture, Oct. 7 th Introduction to Computer Systems 15 213, fall 2009 12 th Lecture, Oct. 7 th Instructors: Majd Sakr and Khaled Harras Last Time Cache Organization Memory Mountain Optimization for the memory hierarchy Cache

More information

CSE351 Inaugural Edi7on Spring

CSE351 Inaugural Edi7on Spring Today Excep7onal Control Flow Processes CSE351 Inaugural Edi7on Spring 2010 1 Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets) a sequence

More information

CS3733: Operating Systems

CS3733: Operating Systems Outline CS3733: Operating Systems Topics: Programs and Processes (SGG 3.1-3.2; USP 2) Programs and Processes States of a process and transitions PCB: Process Control Block Process (program image) in memory

More information

Exceptions, Processes and Signals

Exceptions, Processes and Signals Exceptions, Processes and Signals Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed

More information

Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process?

Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process? Processes and control flow Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process? 1 Control Flow Processors do only one thing:

More information

Approaches to Concurrency

Approaches to Concurrency PROCESS AND THREADS Approaches to Concurrency Processes Hard to share resources: Easy to avoid unintended sharing High overhead in adding/removing clients Threads Easy to share resources: Perhaps too easy

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 19

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 19 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 19 LAST TIME Introduced UNIX signals A kernel facility that provides user-mode exceptional control flow Allows many hardware-level exceptions

More information

Exceptional Control Flow: Exceptions and Processes

Exceptional Control Flow: Exceptions and Processes Exceptional Control Flow: Exceptions and Processes 15-213 : Introduction to Computer Systems 14 th Lecture, June 21, 2018 Instructor: Brian Railing 1 Today Exceptional Control Flow Exceptions Processes

More information

!"#$%&'()*+,'(-.'*+/*'01+!"#$%&'(2+)(3+4.'#$22$2

!#$%&'()*+,'(-.'*+/*'01+!#$%&'(2+)(3+4.'#$22$2 !"#$%&'()*+,'(-.'*+/*'01+!"#$%&'(2+)(3+4.'#$22$2!"#$%&'()*+,-./01-*(+-(!-23/+4,("56+426!"#$%&'$(%)( 78-296(!:(;,466-/. 1,'(-.'*+/*'0 4.'#$22'.2+3'+'(*>+'($+-=8(?1 (9(!?@(6A23B5(,49.6(9*.(4C40/+46(DA*+4,3,4+6E(

More information

Computer Science & Engineering Department I. I. T. Kharagpur. Operating System: CS rd Year CSE: 5th Semester (Autumn ) Lecture VII

Computer Science & Engineering Department I. I. T. Kharagpur. Operating System: CS rd Year CSE: 5th Semester (Autumn ) Lecture VII Computer Science & Engineering Department I. I. T. Kharagpur Operating System: CS33007 3rd Year CSE: 5th Semester (Autumn 2006-2007) Lecture VII Goutam Biswas Date: 4th September, 2006 1 Signals Signals

More information

Virtual Memory I. CSE 351 Autumn Instructor: Justin Hsia

Virtual Memory I. CSE 351 Autumn Instructor: Justin Hsia Virtual Memory I CSE 351 Autumn 2018 Instructor: Justin Hsia Teaching Assistants: Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson Sophie Tian

More information

Excep&onal+Control+Flow:++ Excep&ons+and+Processes+ + 15C213':'Introduc;on'to'Computer'Systems' 14 th 'Lecture,'Oct.'15,'2015'

Excep&onal+Control+Flow:++ Excep&ons+and+Processes+ + 15C213':'Introduc;on'to'Computer'Systems' 14 th 'Lecture,'Oct.'15,'2015' Excep&onal+Control+Flow:++ Excep&ons+and+Processes+ + 15C213':'Introduc;on'to'Computer'Systems' 14 th 'Lecture,'Oct.'15,'2015' Instructors:'' Randal'E.'Bryant'and'David'R.'O Hallaron' 1 Today+! Excep&onal+Control+Flow+!

More information

Processes, Virtual Memory I

Processes, Virtual Memory I Processes, Virtual Memory I CSE 351 Summer 2018 Instructor: Justin Hsia Teaching Assistants: Josie Lee Natalie Andreeva Teagan Horkan http://rebrn.com/re/bad-chrome-1162082/ Administrivia Homework 4 due

More information

Preview. Process Termination. wait and waitpid() System Call. wait and waitpid() System Call. waitpid() System Call 10/23/2018

Preview. Process Termination. wait and waitpid() System Call. wait and waitpid() System Call. waitpid() System Call 10/23/2018 Preview Process Termination The waitpid() System Call The system() System Call Concept of Signals Linux Signals The signal System Call Unreliable Signals Signal() System Call The kill() and raise() System

More information

Processes. CSE 351 Spring Instructor: Ruth Anderson

Processes. CSE 351 Spring Instructor: Ruth Anderson Processes CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Midterms Graded If you did not

More information

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Roadmap. Java: Assembly language: OS: Machine code: Computer system: Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: Computer system: get_mpg: pushq movq... popq ret %rbp %rsp, %rbp

More information

Processes, Signals, I/O, Shell Lab : Introduc>on to Computer Systems Recita>on 9: Monday, Oct. 21, 2013 Marjorie Carlson Sec>on A

Processes, Signals, I/O, Shell Lab : Introduc>on to Computer Systems Recita>on 9: Monday, Oct. 21, 2013 Marjorie Carlson Sec>on A Processes, Signals, I/O, Shell Lab 15-213: Introduc>on to Computer Systems Recita>on 9: Monday, Oct. 21, 2013 Marjorie Carlson Sec>on A 1 Agenda News Shell Lab Overview Processes Overview Important func2ons

More information

System Programming. Process Control II

System Programming. Process Control II Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Terminating a process

More information

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Processes Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu OS Internals User space shell ls trap shell ps Kernel space File System Management I/O

More information

Operating System Structure

Operating System Structure Operating System Structure CSCI 4061 Introduction to Operating Systems Applications Instructor: Abhishek Chandra Operating System Hardware 2 Questions Operating System Structure How does the OS manage

More information

IC221: Systems Programming 12-Week Written Exam [SOLUTIONS]

IC221: Systems Programming 12-Week Written Exam [SOLUTIONS] IC221: Systems Programming 12-Week Written Exam [SOLUTIONS] April 2, 2014 Answer the questions in the spaces provided on the question sheets. If you run out of room for an answer, continue on the back

More information

Recitation 8 Processes, Signals, Tshlab

Recitation 8 Processes, Signals, Tshlab 15-213 Recitation 8 Processes, Signals, Tshlab 22 October 2018 1 Outline Cachelab Style Process Lifecycle Signal Handling 2 Cachelab Style Grading Style grades will be available "soon" Click on your score

More information

Processes. Processes (cont d)

Processes. Processes (cont d) Processes UNIX process creation image-file arg1 arg2 Shell command line example ls -l Equivalent to /bin/ls -l Why? How do you find out where the image file is? Background processes ls -l & Execute a process

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Sciences and Engineering

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Sciences and Engineering INTERNAL ASSESSMENT TEST 2 Solutions 1. Explain the working of the waitpid() API with the help of a program. The program needs to take 2 command line arguments: the first argument should be used as the

More information

Process Control. Philipp Koehn. 23 April 2018

Process Control. Philipp Koehn. 23 April 2018 Process Control Philipp Koehn 23 April 2018 Control Flow 1 The CPU executes one instruction after another Typically, they are next to each other in memory (unless jumps, branches, and returns from subroutine)

More information

ACSC 372 Systems Programming. exec() Functions. Outline

ACSC 372 Systems Programming. exec() Functions. Outline Outline ACSC 372 Systems Programming Lecture 12: Process & Signals (Chapter 8,10 - Stevens & Rago) exec() Functions (ch. 8.10) System Callsystem() (ch. 8.13) Signals in C (ch. 10.1, ch. 10.2, ch. 10.3)

More information

Process. Signal #8. Signals are software interrupts from unexpected events. a power failure. an alarm clock. the death of a child process

Process. Signal #8. Signals are software interrupts from unexpected events. a power failure. an alarm clock. the death of a child process Linux/UNIX Programming 문양세강원대학교 IT특성화대학컴퓨터과학전공 Signals Signals are software interrupts from unexpected events an illegal operation (e.g., divide by 0) a power failure an alarm clock the death of a child

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 18 LAST TIME: OVERVIEW Expanded on our process abstraction A special control process manages all other processes Uses the same process abstraction

More information

Altering the Control Flow

Altering the Control Flow Altering the Control Flow Up to Now: two mechanisms for changing control flow: Jumps and branches Call and return using the stack discipline. Both react to changes in program state. Insufficient for a

More information

CS 4410, Fall 2017 Project 1: My First Shell Assigned: August 27, 2017 Due: Monday, September 11:59PM

CS 4410, Fall 2017 Project 1: My First Shell Assigned: August 27, 2017 Due: Monday, September 11:59PM CS 4410, Fall 2017 Project 1: My First Shell Assigned: August 27, 2017 Due: Monday, September 11th @ 11:59PM Introduction The purpose of this assignment is to become more familiar with the concepts of

More information

Recitation Processes, Signals,UNIX error handling

Recitation Processes, Signals,UNIX error handling 15-213 Recitation Processes, Signals,UNIX error handling Section X - TA name 18 March 2019 Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition 1 Outline Logistics Process

More information

System Calls and Signals: Communication with the OS. System Call. strace./hello. Kernel. Context Switch

System Calls and Signals: Communication with the OS. System Call. strace./hello. Kernel. Context Switch System Calls and Signals: Communication with the OS Jonathan Misurda jmisurda@cs.pitt.edu System Call An operation (function) that an OS provides for running applications to use CS 1550 2077 strace./hello

More information

Foundations of Computer Systems

Foundations of Computer Systems 18-600 Foundations of Computer Systems Lecture 15: Exceptional Control Flow I: Exceptions and Processes John P. Shen & Zhiyi Yu October 19, 2016 18-600 SE PL OS CA Required Reading Assignment: Chapter

More information

UNIX System Programming. Overview. 2. Signal Types (31 in POSIX) Signal Sources. Signals. 1. Definition

UNIX System Programming. Overview. 2. Signal Types (31 in POSIX) Signal Sources. Signals. 1. Definition UNIX System Programming Signals Objectives Introduce signals Concentrate on sigaction() function 1730 UNIX System Programming Signals Maria Hybinette 1 Overview 1. Definition 2. Signal Types 3. Generating

More information

CSC374, Spring 2010 Lab Assignment 1: Writing Your Own Unix Shell

CSC374, Spring 2010 Lab Assignment 1: Writing Your Own Unix Shell CSC374, Spring 2010 Lab Assignment 1: Writing Your Own Unix Shell Contact me (glancast@cs.depaul.edu) for questions, clarification, hints, etc. regarding this assignment. Introduction The purpose of this

More information

Altering the Control Flow

Altering the Control Flow Altering the Control Flow Up to Now: two mechanisms for changing control flow: Jumps and branches Call and return using the stack discipline. Both react to changes in program state. Insufficient for a

More information

CSci 4061 Introduction to Operating Systems. Processes in C/Unix

CSci 4061 Introduction to Operating Systems. Processes in C/Unix CSci 4061 Introduction to Operating Systems Processes in C/Unix Process as Abstraction Talked about C programs a bit Program is a static entity Process is an abstraction of a running program provided by

More information

CSCI Computer Systems Fundamentals Shell Lab: Writing Your Own Unix Shell

CSCI Computer Systems Fundamentals Shell Lab: Writing Your Own Unix Shell CSCI 6050 - Computer Systems Fundamentals Shell Lab: Writing Your Own Unix Shell Introduction The purpose of this assignment is to become more familiar with the concepts of process control and signalling.

More information

Foundations of Computer Systems

Foundations of Computer Systems 18-600 Foundations of Computer Systems Lecture 12: Exceptional Control Flow I: Exceptions and Processes October 9, 2017 18-600 SE PL OS CA Required Reading Assignment: Chapter 8 of CS:APP (3 rd edition)

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 17: Processes, Pipes, and Signals Cristina Nita-Rotaru Lecture 17/ Fall 2013 1 Processes in UNIX UNIX identifies processes via a unique Process ID Each process also knows

More information

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430 Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on

More information