DOC PREVIEW
CMU CS 15213 - class17

This preview shows page 1-2-17-18-19-36-37 out of 37 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

15 213 The course that gives CMU its Zip Exceptional Control Flow Part II Oct 22 2002 Topics n n n n class17 ppt Process Hierarchy Shells Signals Nonlocal jumps ECF Exists at All Levels of a System Exceptions n Hardware and operating system kernel software Previous Lecture Concurrent processes n Hardware timer and kernel software Signals n Kernel software This Lecture Non local jumps n 2 Application code 15 213 F 02 The World of Multitasking System Runs Many Processes Concurrently n Process executing program l State consists of memory image register values program counter n Continually switches from one process to another l Suspend process when it needs I O resource or timer event occurs l Resume process when I O available or given scheduling priority n Appears to user s as if all processes executing simultaneously l Even though most systems can only execute one process at a time l Except possibly with lower performance than if running alone 3 15 213 F 02 Programmer s Model of Multitasking Basic Functions n fork spawns new process l Called once returns twice n exit terminates own process l Called once never returns l Puts it into zombie status n n wait and waitpid wait for and reap terminated children execl and execve run a new program in an existing process l Called once normally never returns Programming Challenge n n Understanding the nonstandard semantics of the functions Avoiding improper use of system resources l E g Fork bombs can disable a system 4 15 213 F 02 Unix Process Hierarchy 0 init 1 Daemon e g httpd Login shell Child Child Grandchild 5 Child Grandchild 15 213 F 02 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 0 Process 0 handcrafted kernel process Process 0 forks child process 1 init 1 6 Child process 1 execs sbin init 15 213 F 02 Unix Startup Step 2 0 etc inittab Daemons e g ftpd httpd 7 init 1 getty init forks and execs daemons per etc inittab and forks and execs a getty program for the console 15 213 F 02 Unix Startup Step 3 0 init 1 login 8 The getty process execs a login program 15 213 F 02 Unix Startup Step 4 0 init 1 tcsh 9 login reads login and passwd if OK it execs a shell if not OK it execs another getty 15 213 F 02 Shell Programs A shell is an application program that runs programs on behalf of the user n sh Original Unix Bourne Shell n csh BSD Unix C Shell tcsh Enhanced C Shell bash Bourne Again Shell n int main char cmdline MAXLINE while 1 read printf Fgets cmdline MAXLINE stdin if feof stdin exit 0 10 Execution is a sequence of read evaluate steps evaluate eval cmdline 15 213 F 02 Simple Shell eval Function void eval char cmdline char argv MAXARGS argv for execve int bg should the job run in bg or fg pid t pid process id bg parseline cmdline argv if builtin command argv if pid Fork 0 child runs user job if execve argv 0 argv environ 0 printf s Command not found n argv 0 exit 0 11 if bg parent waits for fg job to terminate int status if waitpid pid status 0 0 unix error waitfg waitpid error else otherwise don t wait for bg job printf d s pid cmdline 15 213 F 02 Problem with Simple Shell Example Shell correctly waits for and reaps foreground jobs But what about background jobs n Will become zombies when they terminate n Will never be reaped because shell typically will not terminate n Creates a memory leak that will eventually crash the kernel when it runs out of memory Solution Reaping background jobs requires a mechanism called a signal 12 15 213 F 02 Signals A signal is a small message that notifies a process that an event of some type has occurred in the system n n n n ID Kernel abstraction for exceptions and interrupts Sent from the kernel sometimes at the request of another process to a process Different signals are identified by small integer ID s The only information in a signal is its ID and the fact that it arrived Name 2 SIGINT 9 SIGKILL 11 14 SIGSEGV SIGALRM 17 SIGCHLD 13 Default Action Terminate Corresponding Event Interrupt from keyboard ctl c Terminate Kill program cannot override or ignore Terminate Dump Segmentation violation Terminate Timer signal Ignore Child stopped or terminated 15 213 F 02 Signal Concepts Sending a signal n Kernel sends delivers a signal to a destination process by updating some state in the context of the destination process n Kernel sends a signal for one of the following reasons l Kernel has detected a system event such as divide by zero SIGFPE or the termination of a child process SIGCHLD l Another process has invoked the kill system call to explicitly request the kernel to send a signal to the destination process 14 15 213 F 02 Signal Concepts cont Receiving a signal n A destination process receives a signal when it is forced by the kernel to react in some way to the delivery of the signal n Three possible ways to react l Ignore the signal do nothing l Terminate the process l Catch the signal by executing a user level function called a signal handler Akin to a hardware exception handler being called in response to an asynchronous interrupt 15 15 213 F 02 Signal Concepts cont A signal is pending if it has been sent but not yet received n There can be at most one pending signal of any particular type n Important Signals are not queued l If a process has a pending signal of type k then subsequent signals of type k that are sent to that process are discarded A process can block the receipt of certain signals n Blocked signals can be delivered but will not be received until the signal is unblocked A pending signal is received at most once 16 15 213 F 02 Signal Concepts Kernel maintains pending and blocked bit vectors in the context of each process n pending represents the set of pending signals l Kernel sets bit k in pending whenever a signal of type k is delivered l Kernel clears bit k in pending whenever a signal of type k is received n blocked represents the set of blocked signals l Can be set and cleared by the application using the sigprocmask function 17 15 213 F 02 Process Groups Every process belongs to exactly one process group pid 10 pgid 10 pid 20 pgid 20 Foreground job Child Child pid 21 pgid 20 pid 22 pgid 20 Foreground process group 20 18 Shell Background job 1 pid 32 pgid 32 Background process group 32 Background job …


View Full Document

CMU CS 15213 - class17

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download class17
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view class17 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view class17 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?