Exceptional Control Flow Part II October 18, 2006ECF Exists at All Levels of a SystemThe World of MultitaskingProgrammer’s Model of MultitaskingUnix Process HierarchyThe ps commandThe ps Command (cont.)Unix Startup: Step 1Some PC Start-up DetailsSlide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Unix Startup: Step 2Unix Startup: Step 3Unix Startup: Step 4Shell ProgramsSimple Shell eval FunctionProblem with Simple Shell ExampleSignalsSignal ConceptsSignal Concepts (continued)Slide 26Signal ConceptsProcess GroupsSending Signals with kill ProgramSending Signals from the KeyboardExample of ctrl-c and ctrl-zSending Signals with kill FunctionReceiving SignalsDefault ActionsInstalling Signal HandlersSignal Handling ExampleSignals Handlers as Concurrent FlowsAnother View of Signal Handlers as Concurrent FlowsSignal Handler FunkinessLiving With Nonqueuing SignalsSignal Handler Funkiness (Cont.)A Program That Reacts to Externally Generated Events (ctrl-c)A Program That Reacts to Internally Generated EventsNonlocal Jumps: setjmp/longjmpsetjmp/longjmp (cont)setjmp/longjmp ExampleLimitations of Nonlocal JumpsLimitations of Long Jumps (cont.)Putting It All Together: A Program That Restarts Itself When ctrl-c’dSummaryExceptional Control FlowPart IIOctober 18, 2006Exceptional Control FlowPart IIOctober 18, 2006TopicsTopicsProcess HierarchyShellsSignalsNonlocal jumpsclass15.ppt15-213“The course that gives CMU its Zip!”– 2 –15-213, F’06ECF Exists at All Levels of a SystemECF Exists at All Levels of a SystemExceptionsExceptionsHardware and operating system kernel softwareConcurrent processesConcurrent processesHardware timer and kernel softwareSignalsSignalsKernel softwareNon-local jumpsNon-local jumpsApplication codePrevious LectureThis Lecture– 3 –15-213, F’06The World of MultitaskingThe World of MultitaskingSystem Runs Many Processes ConcurrentlySystem Runs Many Processes ConcurrentlyProcess: executing programState consists of memory image + register values + program counterContinually switches from one process to anotherSuspend process when it needs I/O resource or timer event occursResume process when I/O available or given scheduling priorityAppears to user(s) as if all processes executing simultaneouslyEven though most systems can only execute one process at a timeExcept possibly with lower performance than if running alone– 4 –15-213, F’06Programmer’s Model of MultitaskingProgrammer’s Model of MultitaskingBasic FunctionsBasic Functionsfork() spawns new processCalled once, returns twiceexit() terminates own processCalled once, never returnsPuts it into “zombie” statuswait() and waitpid() wait for and reap terminated childrenexecl() and execve() run a new program in an existing processCalled once, (normally) never returnsProgramming ChallengeProgramming ChallengeUnderstanding the nonstandard semantics of the functionsAvoiding improper use of system resourcesE.g. “Fork bombs” can disable a system.– 5 –15-213, F’06Unix Process HierarchyUnix Process HierarchyLogin shellChildChildChildGrandchildGrandchild[0]Daemone.g. httpdinit [1]– 6 –15-213, F’06The ps commandThe ps commandUSER PID TTY STAT COMMANDUSER PID TTY STAT COMMANDroot 1 ? S init [3]root 1 ? S init [3]root 2 ? SW [keventd]root 2 ? SW [keventd]root 3 ? SWN [ksoftirqd_CPU0]root 3 ? SWN [ksoftirqd_CPU0]root 4 ? SW [kswapd]root 4 ? SW [kswapd]root 5 ? SW [bdflush]root 5 ? SW [bdflush]root 6 ? SW [kupdated]root 6 ? SW [kupdated]root 9 ? SW< [mdrecoveryd]root 9 ? SW< [mdrecoveryd]root 12 ? SW [scsi_eh_0]root 12 ? SW [scsi_eh_0]root 397 ? S /sbin/pump -i eth0root 397 ? S /sbin/pump -i eth0root 484 ? S< /usr/local/sbin/afsd -nosettimeroot 484 ? S< /usr/local/sbin/afsd -nosettimeroot 533 ? S syslogd -m 0root 533 ? S syslogd -m 0root 538 ? S klogd -2root 538 ? S klogd -2rpc 563 ? S portmaprpc 563 ? S portmaprpcuser 578 ? S rpc.statdrpcuser 578 ? S rpc.statddaemon 696 ? S /usr/sbin/atddaemon 696 ? S /usr/sbin/atdroot 713 ? S /usr/local/etc/nanny -init /etc/nanny.confroot 713 ? S /usr/local/etc/nanny -init /etc/nanny.confmmdf 721 ? S \_ /usr/local/etc/deliver -b -csmtpcmummdf 721 ? S \_ /usr/local/etc/deliver -b -csmtpcmuroot 732 ? S \_ /usr/local/sbin/named -froot 732 ? S \_ /usr/local/sbin/named -froot 738 ? S \_ /usr/local/sbin/sshd -Droot 738 ? S \_ /usr/local/sbin/sshd -Droot 739 ? S<L \_ /usr/local/etc/ntpd -nroot 739 ? S<L \_ /usr/local/etc/ntpd -nroot 752 ? S<L | \_ /usr/local/etc/ntpd -nroot 752 ? S<L | \_ /usr/local/etc/ntpd -nroot 753 ? S<L | \_ /usr/local/etc/ntpd -nroot 753 ? S<L | \_ /usr/local/etc/ntpd -nroot 744 ? S \_ /usr/local/sbin/zhm -n zephyr-1.srv.cmroot 744 ? S \_ /usr/local/sbin/zhm -n zephyr-1.srv.cmroot 774 ? S gpm -t ps/2 -m /dev/mouseroot 774 ? S gpm -t ps/2 -m /dev/mouseroot 786 ? S crondroot 786 ? S crondUnix> ps aux -w --forest(output edited to fit slide)– 7 –15-213, F’06The ps Command (cont.)The ps Command (cont.)USER PID TTY STAT COMMANDUSER PID TTY STAT COMMANDroot 889 tty1 S /bin/login -- agnroot 889 tty1 S /bin/login -- agnagn 900 tty1 S \_ xinit -- :0agn 900 tty1 S \_ xinit -- :0root 921 ? SL \_ /etc/X11/X -auth /usr1/agn/.Xauthority :0root 921 ? SL \_ /etc/X11/X -auth /usr1/agn/.Xauthority :0agn 948 tty1 S \_ /bin/sh /afs/cs.cmu.edu/user/agn/.xinitrcagn 948 tty1 S \_ /bin/sh /afs/cs.cmu.edu/user/agn/.xinitrcagn 958 tty1 S \_ xterm -geometry 80x45+1+1 -C -j -ls -nagn 958 tty1 S \_ xterm -geometry 80x45+1+1 -C -j -ls -nagn 966 pts/0
View Full Document