Exceptional Control FlowPart IIOctober 18, 2006Exceptional Control FlowPart IIOctober 18, 2006TopicsTopics Process Hierarchy Shells Signals Nonlocal 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 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’06The 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’06Programmer’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’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 [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’06The 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 958 tty1 S \\_ _ xtermxterm--geometry 80x45+1+1 geometry 80x45+1+1 --C C --j j --lsls--nnagn 966 pts/0 S | agn 966 pts/0 S | \\_ _ --tcshtcshagn 1184 pts/0 S | agn 1184 pts/0 S | \\_ /usr/local/bin/wish8.0 _ /usr/local/bin/wish8.0 --f /f /usrusragn 1212 pts/0 S | | agn 1212 pts/0 S | | \\_ /usr/local/bin/wish8.0 _ /usr/local/bin/wish8.0 --f f agn 3346 pts/0 S | | agn 3346 pts/0 S | | \\_ _ aspellaspell--a a --SSagn 1191 pts/0 S | agn 1191 pts/0 S | \\_ /bin/_ /bin/shsh//usr/local/libexec/mozusr/local/libexec/mozagn 1204 8 pts/0 S | agn 1204 8 pts/0 S | \\_ /_ /usr/local/libexec/mozillausr/local/libexec/mozillaagn 1207 8 pts/0 S | agn 1207 8 pts/0 S | \\_ /_ /usr/local/libexec/mozusr/local/libexec/mozagn 1208 8 pts/0 S | | agn 1208 8 pts/0 S | | \\_ /_ /usr/local/libexecusr/local/libexecagn 1209 8 pts/0 S | | agn 1209 8 pts/0 S
View Full Document