Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems CMPSC 473 Processes (4) September 19 2008 - Lecture 10 Instructor: Bhuvan Urgaonkar.

Similar presentations


Presentation on theme: "Operating Systems CMPSC 473 Processes (4) September 19 2008 - Lecture 10 Instructor: Bhuvan Urgaonkar."— Presentation transcript:

1 Operating Systems CMPSC 473 Processes (4) September 19 2008 - Lecture 10 Instructor: Bhuvan Urgaonkar

2 Overview of Process- related Topics How a process is born –Parent/child relationship –fork, clone, … How it leads its life –Loaded: Later in the course –Executed CPU scheduling Context switching Where a process “lives”: Address space –OS maintains some info. for each process: PCB –Process = Address Space + PCB How processes request services from the OS –System calls How processes communicate Some variants of processes: LWPs and threads How processes die Done Partially done

3 Kernel Mode Stack thread_info structure PCB (task_struct) esp curent Stack Since KM stacks make little use of the stack, only a few thousand bytes suffice –An example of “Design for the most common case”, we’ll see more –Linux: 8KB, thread_info 52 bytes thread_info task

4 Kernel Mode Stack thread_info structure PCB (task_struct) esp curent Stack Since KM stacks make little use of the stack, only a few thousand bytes suffice –An example of “Design for the most common case”, we’ll see more –Linux: 8KB Why combine KM stack and thread_info into a union? thread_info union thread_union { struct thread_info thread_info; unsigned long stack[2048]; }; task

5 Kernel Mode Stack thread_info structure PCB (task_struct) esp curent Stack Since KM stacks make little use of the stack, only a few thousand bytes suffice –An example of “Design for the most common case”, we’ll see more –Linux: KM Stack 8KB, thread_info 52 bytes Why combine KM stack and thread_info into a union? –You might think spatial locality –The kernel can easily obtain the address of the thread_info structure of the process currently running on the CPU from the value of the esp register –task field is at offset 0 –Other benefits apply to multi-processors: makes it easy to efficiently find the current process on each processor Earlier approach: Have an array of current pointers thread_info task union thread_union { struct thread_info thread_info; unsigned long stack[2048]; };

6 Resource Limits Kernel imposes limits on the amount of resources a process may have –E.g., address space size, open files Linux: For each resource, for each process struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; } System calls: getrlimit (), setrlimit () to increase upto some max allowed by kernel

7 Relationships among processes Several relatives of P recorded in its PCB –real_parent Process that called fork to create P Or init (process 1) –parent Usually real_parent –Kernel signals this parent process when child exits Or process that issues ptrace () to monitor P Pop quiz: If you run a background process and exit the shell, who is the parent of the process? –children –siblings Why maintain these?

8 Process Switch Suspend the current process and resume a previously suspended process –Also called context switch or task switch What does the kernel need to save when suspending a process? –Hint: The entire address space is already saved (either in memory or on swap space). What else would the process need when it has to be resumed?

9 Process Switch Suspend the current process and resume a previously suspended process –Also called context switch or task switch What does the kernel need to save when suspending a process? –Hint: The entire address space is already saved (either in memory or on swap space). What else would the process need when it has to be resumed? –CPU registers This is called the hardware context of the process Linux: Part of h/w context saved within PCB, rest on kernel mode stack (why?)

10 Process Switch So process switch involves –Saving h/w context of currently running process –Restoring h/w context of process to resume Who decides which process to resume?

11 Process Switch So process switch involves –Saving h/w context of currently running process –Restoring h/w context of process to resume Who decides which process to resume? –The CPU scheduler –Generic code for a process switch next = schedule (prev); switch_to (next, prev); ------> GORY! SKIPPING!! blah blah blah Note: next starts executing not blah. How? Project 1 will give you a taste of this :)

12 Creating Processes fork () Take 1: Used in older kernels –Create a copy of the entire address space of the parent –Create a new PCB for the new process –Update parent, children, sibling pointers –Place the new process in the ready queue S. L. O. W.

13 Creating Processes fork () Problems with Take 1 –Child rarely needs to read/modify ALL the resources inherited from the parent –Often, it immediately issues an execve() rendering all the effort that went into copying the address space useless!

14 Creating Processes fork () What modern kernels do to avoid this waste of precious CPU time COW!! Something in the way she moos …

15 Creating Processes: COW fork () What modern kernels do to avoid this waste of precious CPU time –Use COW! –Copy-On-Write –Basic idea: Postpone work till the last minute –Sounds familiar? Think assignments, quizzes, …


Download ppt "Operating Systems CMPSC 473 Processes (4) September 19 2008 - Lecture 10 Instructor: Bhuvan Urgaonkar."

Similar presentations


Ads by Google