Introduction to Computer Systems 15-213, fall 2009 14th Lecture, Oct. 14thECF 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 Concepts Process 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.)Putting It All Together: A Program That Restarts Itself When ctrl-c’dSummaryTodaySending 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 200914thLecture, Oct. 14thInstructors:Majd Sakr and Khaled HarrasCarnegie MellonECF Exists at All Levels of a System Exceptions Hardware and operating system kernel software Signals Kernel software Non‐local jumps Application codePrevious LectureThis LectureCarnegie MellonToday Multitasking, shells Signals Long jumps More on signalsCarnegie MellonThe World of Multitasking System runs many processes concurrently Process: executing program State includes memory image + register values + program counter Regularly switches from one process to another Suspend process when it needs I/O resource or timer event occurs Resume process when I/O available or given scheduling priority Appears to user(s) as if all processes executing simultaneously Even though most systems can only execute one process at a time Except possibly with lower performance than if running aloneCarnegie MellonProgrammer’s Model of Multitasking Basic functions fork() spawns new process Called once, returns twice exit() terminates own process Called once, never returns Puts it into “zombie” status wait() and waitpid() wait for and reap terminated children execl() and execve() run new program in existing process Called once, (normally) never returns Programming challenge Understanding the nonstandard semantics of the functions Avoiding improper use of system resources E.g. “Fork bombs” can disable a systemCarnegie MellonUnix Process HierarchyLogin shellChildChildChildGrandchildGrandchild[0]Daemone.g. httpdinit [1]Carnegie MellonThe ps command USER PID TTY STAT COMMAND root 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 eth0 root 484 ? S< /usr/local/sbin/afsd -nosettime root 533 ? S syslogd -m 0 root 538 ? S klogd -2 rpc 563 ? S portmap rpcuser 578 ? S rpc.statd daemon 696 ? S /usr/sbin/atd root 713 ? S /usr/local/etc/nanny -init /etc/nanny.conf mmdf 721 ? S \_ /usr/local/etc/deliver -b -csmtpcmu root 732 ? S \_ /usr/local/sbin/named -f root 738 ? S \_ /usr/local/sbin/sshd -D root 739 ? S<L \_ /usr/local/etc/ntpd -n root 752 ? S<L | \_ /usr/local/etc/ntpd -n root 753 ? S<L | \_ /usr/local/etc/ntpd -n root 744 ? S \_ /usr/local/sbin/zhm -n zephyr-1.srv.cm root 774 ? S gpm -t ps/2 -m /dev/mouse root 786 ? S crondUnix> ps aux -w --forest(output edited to fit slide)Carnegie Mellon USER PID TTY STAT COMMAND root 889 tty1 S /bin/login -- agn agn 900 tty1 S \_ xinit -- :0 root 921 ? SL \_ /etc/X11/X -auth /usr1/agn/.Xauthority :0 agn 948 tty1 S \_ /bin/sh /afs/cs.cmu.edu/user/agn/.xinitrc agn 958 tty1 S \_ xterm -geometry 80x45+1+1 -C -j -ls -n agn 966 pts/0 S | \_ -tcsh agn 1184 pts/0 S | \_ /usr/local/bin/wish8.0 -f /usr agn 1212 pts/0 S | | \_ /usr/local/bin/wish8.0 -f agn 3346 pts/0 S | | \_ aspell -a -S agn 1191 pts/0 S | \_ /bin/sh /usr/local/libexec/moz agn 1204 8 pts/0 S | \_ /usr/local/libexec/mozilla agn 1207 8 pts/0 S | \_ /usr/local/libexec/moz agn 1208 8 pts/0 S | | \_ /usr/local/libexec agn 1209 8 pts/0 S | | \_ /usr/local/libexec agn 17814 8 pts/0 S | | \_ /usr/local/libexec agn 2469 pts/0 S | \_ usr/local/lib/Acrobat agn 2483 pts/0 S | \_ java_vm agn 2484 pts/0 S | \_ java_vm agn 2485 pts/0 S | \_ java_vm agn 3042 pts/0 S | \_ java_vm agn 959 tty1 S \_ /bin/sh /usr/local/libexec/kde/bin/sta agn 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
View Full Document