ECF Exists at All Levels of a System 15 213 Exceptions The course that gives CMU its Zip Hardware and operating system kernel software Exceptional Control Flow Part II October 18 2006 Concurrent processes Topics Signals Process Hierarchy Shells Signals Nonlocal jumps Previous Lecture Hardware timer and kernel software Kernel software This Lecture NonNon local jumps Application code 15 213 F 06 2 class15 ppt The World of Multitasking Programmer s Model of Multitasking System Runs Many Processes Concurrently Basic Functions Process executing program fork spawns new process exit terminates own process z Called once returns twice z State consists of memory image register values program counter z Called once never returns z Puts it into zombie status Continually switches from one process to another z Suspend process when it needs I O resource or timer event occurs z Resume process when I O available or given scheduling priority Appears to user s as if all processes executing simultaneously z Called once normally never returns z Even though most systems can only execute one process at a time z Except possibly with lower performance than if running alone wait and waitpid wait for and reap terminated children execl and execve run a new program in an existing process Programming Challenge Understanding the nonstandard semantics of the functions Avoiding improper use of system resources z E g Fork bombs can disable a system 3 15 213 F 06 4 15 213 F 06 The ps command Unix Process Hierarchy output edited to fit slide Unix ps aux w forest 0 USER root root root root root root root root root root root root rpc rpcuser daemon root mmdf root root root root root root root root init 1 Daemon e g httpd Login shell Child Child Grandchild Child Grandchild 15 213 F 06 5 The ps Command cont USER root agn root agn agn agn agn agn agn agn agn agn agn agn agn agn agn agn agn agn agn agn PID 889 900 921 948 958 966 1184 1212 3346 1191 1204 1207 1208 1209 17814 2469 2483 2484 2485 3042 959 1020 TTY tty1 tty1 tty1 tty1 pts 0 pts 0 pts 0 pts 0 pts 0 8 pts 0 8 pts 0 8 pts 0 8 pts 0 8 pts 0 pts 0 pts 0 pts 0 pts 0 pts 0 tty1 tty1 PID 1 2 3 4 5 6 9 12 397 484 533 538 563 578 696 713 721 732 738 739 752 753 744 774 786 TTY STAT S SW SWN SW SW SW SW SW S S S S S S S S S S S S L S L S L S S S 15 213 F 06 6 Unix Startup Step 1 1 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 STAT COMMAND S bin login agn S xinit 0 SL etc X11 X auth usr1 agn Xauthority 0 S bin sh bin sh afs cs cmu edu user agn xinitrc S xterm geometry 80x45 1 1 C j ls n S tcsh S usr local bin wish8 0 f usr usr S usr local bin wish8 0 f S aspell a S S bin sh bin sh usr local libexec moz S usr local libexec mozilla usr local libexec mozilla S usr local libexec moz usr local libexec moz S usr local libexec usr local libexec S usr local libexec usr local libexec S usr local libexec usr local libexec S usr local lib Acrobat usr local lib Acrobat S java vm S java vm S java vm S java vm S bin sh bin sh usr local libexec kde bin sta S kwrapper ksmserver 0 15 213 F 06 Process 0 handcrafted kernel process Process 0 forks child process 1 init 1 7 COMMAND init 3 keventd keventd ksoftirqd CPU0 kswapd kswapd bdflush bdflush kupdated kupdated mdrecoveryd mdrecoveryd scsi eh 0 sbin pump i eth0 sbin pump usr local sbin afsd usr local sbin afsd nosettime syslogd m 0 klogd 2 portmap rpc statd usr sbin atd usr sbin atd usr local etc nanny init etc nanny conf usr local etc nanny usr local etc deliver b csmtpcmu usr local etc deliver usr local sbin named usr local sbin named f usr local sbin sshd usr local sbin sshd D usr local etc ntpd usr local etc ntpd n usr local etc ntpd usr local etc ntpd n usr local etc ntpd usr local etc ntpd n usr local sbin zhm usr local sbin zhm n zephyrzephyr 1 srv cm gpm t ps 2 m dev mouse crond 8 Child process 1 execs sbin init 15 213 F 06 Some PC Start up Details Some PC Start up Details Boot Disk CD Floppy Boot Disk CD Floppy CPU CPU 0xffffffff 0xffff0000 0xffffffff 0xffff0000 BIOS ROM 0x00000000 Some PC Start up Details 15 213 F 06 10 Some PC Start up Details Boot Disk CD Floppy Start Execution at 0xfffffff0 BIOS ROM 0x00000000 15 213 F 06 9 Power on Reset Boot Disk CD Floppy CPU CPU 0xffffffff 0xffff0000 0xffffffff 0xffff0000 BIOS ROM BIOS ROM Copy Master Boot Record MBR into memory 0x00007c00 0x00000000 0x00000000 11 15 213 F 06 12 15 213 F 06 Some PC Start up Details Some PC Start up Details Boot Disk CD Floppy Boot Disk CD Floppy CPU CPU 0xffffffff 0xffff0000 0xffffffff 0xffff0000 BIOS ROM BIOS ROM LILO or GRUB is loaded from first sector of active partition BIOS verifies MBR and jumps to 0x00007c00 0x00007c00 0x00000000 0x00007c00 0x00000000 15 213 F 06 13 Some PC Start up Details 15 213 F 06 14 Some PC Start up Details Boot Disk CD Floppy Boot Disk CD Floppy CPU CPU 0xffffffff 0xffff0000 0xffffffff 0xffff0000 BIOS ROM BIOS ROM CPU executes LILO The Linux kernel is loaded and begins initialization 0x00007c00 0x00000000 15 0x00007c00 0x00000000 15 213 F 06 16 15 213 F 06 Unix Startup Step 2 Unix Startup Step 3 0 etc inittab Daemons e g ftpd httpd init 1 getty 0 15 213 F 06 17 Unix Startup Step 4 login The getty process execs a login program 15 213 F 06 18 Shell Programs A shell is an application program that runs programs on behalf of the user 0 init 1 tcsh init 1 init forks and execs daemons per etc inittab and forks and execs a getty program for the console login reads login ID and passwd if OK it execs a shell if not OK it execs another getty sh Original Unix Bourne Shell csh BSD Unix C Shell tcsh Enhanced C Shell bash Bourne Again Shell int main char cmdline MAXLINE while 1 read printf Fgets cmdline MAXLINE stdin if feof stdin exit 0 In case of login on the console xinit may be used instead of a shell to start the window manger Execution is a sequence of read evaluate steps evaluate eval cmdline 19 …
View Full Document