Exceptional Control Flow Part II October 24, 2007ECF 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 DetailsSome PC Start-up DetailsSome PC Start-up DetailsSome PC Start-up DetailsSome PC Start-up DetailsSome PC Start-up DetailsSome PC Start-up DetailsSome PC Start-up DetailsUnix Startup: Step 2Unix Startup: Step 3Unix Startup: Step 4Shell ProgramsSimple Shell eval FunctionProblem with Simple Shell ExampleSignalsSignal Concepts Signal Concepts (continued)Signal Concepts (continued)Signal Concepts Process 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 24, 2007Exceptional Control FlowPart IIOctober 24, 200715-213TopicsTopics Process Hierarchy Shells Signals Nonlocal jumpsclass15.ppt15-213, F’07–2–15-213, F’07ECF Exists at All Levels of a SystemECF Exists at All Levels of a SystemExceptionsExceptions Hardware and operating system kernel softwareConcurrent processesConcurrent processes Hardware timer and kernel softwareSignalsSignals Kernel softwareNonNon--local jumpslocal jumps Application codePrevious LectureThis Lecture–3–15-213, F’07The World of MultitaskingThe World of MultitaskingSystem Runs Many Processes ConcurrentlySystem Runs Many Processes Concurrently Process: executing programz State consists of memory image + register values + program counter Continually switches from one process to anotherz Suspend process when it needs I/O resource or timer event occursz Resume process when I/O available or given scheduling priority Appears to user(s) as if all processes executing simultaneouslyz Even though most systems can only execute one process at a timez Except possibly with lower performance than if running alone–4–15-213, F’07Programmer’s Model of MultitaskingProgrammer’s Model of MultitaskingBasic FunctionsBasic Functions fork() spawns new processz Called once, returns twice exit() terminates own processz Called once, never returnsz Puts it into “zombie” status wait() and waitpid() wait for and reap terminated children execl() and execve() run a new program in an existing processz Called once, (normally) never returnsProgramming ChallengeProgramming Challenge Understanding the nonstandard semantics of the functions Avoiding improper use of system resourcesz E.g. “Fork bombs” can disable a system.–5–15-213, F’07Unix Process HierarchyUnix Process HierarchyLogin shellChildChildChildGrandchildGrandchild[0]Daemone.g. httpdinit [1]–6–15-213, F’07The ps commandThe ps commandUSER PID TTY STAT COMMANDUSER PID TTY STAT COMMANDroot 1 ? S init [3]root 1 ? S init [3]root 2 ? SW [root 2 ? SW [keventdkeventd]]root 3 ? SWN [ksoftirqd_CPU0]root 3 ? SWN [ksoftirqd_CPU0]root 4 ? SW [root 4 ? SW [kswapdkswapd]]root 5 ? SW [root 5 ? SW [bdflushbdflush]]root 6 ? SW [root 6 ? SW [kupdatedkupdated]]root 9 ? SW< [root 9 ? SW< [mdrecoverydmdrecoveryd]]root 12 ? SW [scsi_eh_0]root 12 ? SW [scsi_eh_0]root 397 ? S /root 397 ? S /sbinsbin/pump /pump --i eth0i eth0root 484 ? S< /root 484 ? S< /usr/local/sbin/afsdusr/local/sbin/afsd--nosettimenosettimeroot 533 ? S root 533 ? S syslogdsyslogd--m 0m 0root 538 ? S root 538 ? S klogdklogd--22rpcrpc563 ? S 563 ? S portmapportmaprpcuserrpcuser578 ? S 578 ? S rpc.statdrpc.statddaemon 696 ? S /daemon 696 ? S /usr/sbin/atdusr/sbin/atdroot 713 ? S /root 713 ? S /usrusr/local/etc/nanny /local/etc/nanny --init /etc/nanny.confinit /etc/nanny.confmmdfmmdf721 ? S 721 ? S \\_ /_ /usrusr/local/etc/deliver /local/etc/deliver --b b --csmtpcmucsmtpcmuroot 732 ? S root 732 ? S \\_ /_ /usr/local/sbin/namedusr/local/sbin/named--ffroot 738 ? S root 738 ? S \\_ /_ /usr/local/sbin/sshdusr/local/sbin/sshd--DDroot 739 ? S<L root 739 ? S<L \\_ /_ /usr/local/etc/ntpdusr/local/etc/ntpd--nnroot 752 ? S<L | root 752 ? S<L | \\_ /_ /usr/local/etc/ntpdusr/local/etc/ntpd--nnroot 753 ? S<L | root 753 ? S<L | \\_ /_ /usr/local/etc/ntpdusr/local/etc/ntpd--nnroot 744 ? S root 744 ? S \\_ /_ /usr/local/sbin/zhmusr/local/sbin/zhm--n zephyrn zephyr--1.srv.cm1.srv.cmroot 774 ? S root 774 ? S gpmgpm--t ps/2 t ps/2 --m /dev/mousem /dev/mouseroot 786 ? S root 786 ? S crondcrondUnix> ps aux -w --forest(output edited to fit slide)–7–15-213, F’07The ps Command (cont.)The ps Command (cont.)USER PID TTY STAT COMMANDUSER PID TTY STAT COMMANDroot 889 tty1 S /bin/login root 889 tty1 S /bin/login ----agnagnagn 900 tty1 S agn 900 tty1 S \\_ _ xinitxinit----:0:0root 921 ? SL root 921 ? SL \\_ /etc/X11/X _ /etc/X11/X --auth /usr1/agn/.Xauthority :0auth /usr1/agn/.Xauthority :0agn 948 tty1 S agn 948 tty1 S \\_ /bin/_ /bin/shsh//afs/cs.cmu.edu/user/agn/.xinitrcafs/cs.cmu.edu/user/agn/.xinitrcagn 958 tty1 S agn
View Full Document