Slide 1ECF Exists at All Levels of a SystemTodayThe 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 FunctionWhat Is a “Background Job”?Problem with Simple Shell ExampleECF to the Rescue!TodaySignalsSending a SignalReceiving a SignalSignal Concepts (continued)Signal ConceptsProcess GroupsSending Signals with kill ProgramSending Signals with kill FunctionReceiving SignalsDefault ActionsInstalling Signal HandlersSignal Handling ExampleSignals Handlers as Concurrent FlowsAnother View of Signal Handlers as Concurrent FlowsTodayNonlocal Jumps: setjmp/longjmpsetjmp/longjmp (cont)setjmp/longjmp ExampleLimitations of Nonlocal JumpsLimitations of Long Jumps (cont.)Slide 47SummaryTodaySending Signals from the KeyboardExample of ctrl-c and ctrl-zSignal 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 EventsCarnegie MellonIntroduction to Computer Systems15-213, fall 200914th Lecture, Oct. 14thInstructors: Majd Sakr and Khaled HarrasCarnegie MellonECF Exists at All Levels of a SystemExceptionsHardware and operating system kernel softwareSignalsKernel softwareNon-local jumpsApplication codePrevious LectureThis LectureCarnegie MellonTodayMultitasking, shellsSignalsLong jumpsMore on signalsCarnegie MellonThe World of MultitaskingSystem runs many processes concurrentlyProcess: executing programState includes memory image + register values + program counterRegularly 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 aloneCarnegie MellonProgrammer’s Model of MultitaskingBasic 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 new program in existing processCalled once, (normally) never returnsProgramming challengeUnderstanding the nonstandard semantics of the functionsAvoiding improper use of system resourcesE.g. “Fork bombs” can disable a systemCarnegie MellonUnix Process HierarchyLogin shellChildChildChildGrandchildGrandchild[0]Daemone.g. httpdinit [1]Carnegie MellonThe ps commandUSER PID TTY STAT COMMANDroot 1 ? S init [3]root 2 ? SW [keventd]root 3 ? SWN [ksoftirqd_CPU0]root 4 ? SW [kswapd]root 5 ? SW [bdflush]root 6 ? SW [kupdated]root 9 ? SW< [mdrecoveryd]root 12 ? SW [scsi_eh_0]root 397 ? S /sbin/pump -i eth0root 484 ? S< /usr/local/sbin/afsd -nosettimeroot 533 ? S syslogd -m 0root 538 ? S klogd -2rpc 563 ? S portmaprpcuser 578 ? S rpc.statddaemon 696 ? S /usr/sbin/atdroot 713 ? S /usr/local/etc/nanny -init /etc/nanny.confmmdf 721 ? S \_ /usr/local/etc/deliver -b -csmtpcmuroot 732 ? S \_ /usr/local/sbin/named -froot 738 ? S \_ /usr/local/sbin/sshd -Droot 739 ? S<L \_ /usr/local/etc/ntpd -nroot 752 ? 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 774 ? S gpm -t ps/2 -m /dev/mouseroot 786 ? S crondUnix> ps aux -w --forest(output edited to fit slide)Carnegie MellonUSER PID TTY STAT COMMANDroot 889 tty1 S /bin/login -- agnagn 900 tty1 S \_ xinit -- :0root 921 ? SL \_ /etc/X11/X -auth /usr1/agn/.Xauthority :0agn 948 tty1 S \_ /bin/sh /afs/cs.cmu.edu/user/agn/.xinitrcagn 958 tty1 S \_ xterm -geometry 80x45+1+1 -C -j -ls -nagn 966 pts/0 S | \_ -tcshagn 1184 pts/0 S | \_ /usr/local/bin/wish8.0 -f /usragn 1212 pts/0 S | | \_ /usr/local/bin/wish8.0 -f agn 3346 pts/0 S | | \_ aspell -a -Sagn 1191 pts/0 S | \_ /bin/sh /usr/local/libexec/mozagn 1204 8 pts/0 S | \_ /usr/local/libexec/mozillaagn 1207 8 pts/0 S | \_ /usr/local/libexec/mozagn 1208 8 pts/0 S | | \_ /usr/local/libexecagn 1209 8 pts/0 S | | \_ /usr/local/libexecagn 17814 8 pts/0 S | | \_ /usr/local/libexecagn 2469 pts/0 S | \_ usr/local/lib/Acrobatagn 2483 pts/0 S | \_ java_vmagn 2484 pts/0 S | \_ java_vmagn 2485 pts/0 S | \_ java_vmagn 3042 pts/0 S | \_ java_vmagn 959 tty1 S \_ /bin/sh /usr/local/libexec/kde/bin/staagn 1020 tty1 S \_ kwrapper ksmserverThe ps Command (cont.)Carnegie MellonUnix Startup: Step 1init [1][0]Process 0: handcrafted kernel processChild process 1 execs /sbin/init1. Pushing reset button loads the PC with the address of a small bootstrap program.2. Bootstrap program loads the boot block (disk block 0).3. Boot block program loads kernel binary (e.g., /boot/vmlinux)4. Boot block program passes control to kernel.5. Kernel handcrafts the data structures for process 0.Process 0
View Full Document