Forking & Process Scheduling Vivek Pai / Kai Li Princeton University.

Slides:



Advertisements
Similar presentations
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
Advertisements

A. Frank - P. Weisberg Operating Systems Process Scheduling and Switching.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
The Process Model.
CSE 451: Operating Systems Winter 2006 Module 4 Processes Ed Lazowska Allen Center 570.
Processes CSCI 444/544 Operating Systems Fall 2008.
Forking, w/ Unified VM Wrapup Vivek Pai / Kai Li Princeton University.
OS Spring’03 Introduction Operating Systems Spring 2003.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Preemptive Scheduling Vivek Pai / Kai Li Princeton University.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
Preemptive Scheduling Vivek Pai / Kai Li Princeton University.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Processes CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process Description and Control
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Chapter 3 Process Description and Control
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Processes: program + execution state
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Computer Studies (AL) Operating System Process Management - Process.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
15-410, S’ The Process Jan. 21, 2004 Dave Eckhardt Bruce Maggs L05_Process “System call abuse for fun & profit”
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Scheduler activations Landon Cox March 23, What is a process? Informal A program in execution Running code + things it can read/write Process ≠
Processes and threads.
Chapter 9: Virtual Memory
Protection of System Resources
Unix Process Management
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
System Structure and Process Model
System Structure and Process Model
Processes in Unix, Linux, and Windows
System Structure B. Ramamurthy.
Processes and Non-Preemptive Scheduling
Operating Systems Lecture November 2018.
Processes in Unix, Linux, and Windows
System Structure and Process Model
Operating Systems Lecture 6.
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process & its States Lecture 5.
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Chapter 3: Processes.
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Presentation transcript:

Forking & Process Scheduling Vivek Pai / Kai Li Princeton University

2 Mechanics  Exams not graded –Hopefully, this week  Filesystem project –Extension + bonus? –This wasn’t supposed to happen  Today: forking + scheduling

3 A Quick Review  What have we covered –How to store data via files –How to virtualize memory Every process gets uniform address space Lots of tricks can be played to share memory  What’s left –How to share/virtualize the processor –Having processes communicate/cooperate

4 How To Launch a New Process?  Obvious choice: “start process” system call  But not all processes start the same –“testprogram” versus “testprogram >& outfile” versus “testprogram arg1 arg2 >& outfile”  The “parent” process wants to specify various aspects of the child’s “environment” –Next step: add more parameters to specify environment

5 Can We Generalize?  What happens as more information gets added to the process’s “environment” – more parameters? New system calls? This gets ugly  What’s the most general way of setting up all of the environment?  So, why not allow process setup at any point? –This is the exec( ) system call (and its variants)

6 But We Want a Parent and a Child  The exec call “destroys” the current process  So, instead, destroy a copy of the process –The fork( ) call duplicates the current process –Better yet, don’t tightly couple fork and exec This way, you can customize the child’s environment  So what does fork( ) entail? –Making a copy of everything about the process –Ouch!

7 What Gets Copied  So far, we’ve covered the following: –VM system –File system –Signals  How do we go about copying this information?  What parts are easy to copy, and what’s hard?  What’s the common case with fork/exec? –What needs to get preserved in this scenario?

8 Shared Memory  How to destroy a virtual address space? –Link all PTEs –Reference count  How to swap out/in? –Link all PTEs –Operation on all entries  How to pin/unpin? –Link all PTEs –Reference count Process 1 Process 2 w w Page table Physical pages

Copy-On-Write  Child’s virtual address space uses the same page mapping as parent’s  Make all pages read-only  Make child process ready  On a read, nothing happens  On a write, generates an access fault –map to a new page frame –copy the page over –restart the instruction Parent process Child process r r r r Page table Physical pages

10 Issues of Copy-On-Write  How to destroy an address space –Same as shared memory case?  How to swap in/out? –Same as shared memory  How to pin/unpin –Same as shared memory

11 Process Creation & Termination Four primitives:  Fork – create a copy of this process  Exec – replace this process with this program  Wait – wait for child process to finish  Kill – (potentially) end a running process Processes form a tree – what happens when parent disappears?

12 Signals Asynchronous event delivery mechanism  Examples – FPE, segv, ctrl- c, hang up, resume  Default actions – ignore, abort, core dump  Handler – program- specified routine for signal

13 A Signaling Sidebar  What’s wrong with this program: int randVal; void SigHand(void) { printf(“your rand val is %d\n”, randVal); } int main(int argc, char *argv[]) { set up ctrl-c handler; while (1) { randVal = 0; randVal = 1; … randVal = 9; }

14 Scheduling Primitives  Block – wait on some event/resource –Network packet arrival –Keyboard, mouse input –Disk activity completion  Yield – give up running for now –Directed (let my friend run) –Undirected (let any process run)  Synchronization –We will talk about this later

15 Our Friend, The Transition Diagram Running Blocked Ready Scheduler dispatch Wait for resource Resource becomes available Create a process terminate

16 Process State Transition of Non-Preemptive Scheduling Running Blocked Ready Resource becomes available (move to ready queue) Create a process Terminate (call scheduler) Yield (call scheduler) Block for resource (call scheduler) Scheduler dispatch

17 Who’s Happy Right Now

Scheduler  A non-preemptive scheduler invoked by explicit block or yield calls  The simplest form Scheduler: save current process state (into PCB) choose next process to run dispatch (load PCB and run)  Does this work?

More on Scheduler  Should the scheduler use a special stack? –Yes, because a user process can overflow and it would require another stack to deal with stack overflow  Should the scheduler simply be a kernel process? –You can view it that way because it has a stack, code and its data structure –This process always runs when there is no user process

20 Where Should PCB Be Saved?  Save the PCB on its user stack –Many processors have a special instruction to do it “efficiently” –But, need to deal with the overflow problem –When the process terminates, the PCB vanishes  Save the PCB on the kernel heap data structure –May not be as efficient as saving it on stack –But, it is very flexible and no other problems

21 Physical Memory & Multiprogramming  Memory is a scarce resource  Want to run many programs  Programs need memory to run  What happens when M(a) + M(b) + M(c) > physical mem? Answer: paging. But what if no paging?

22 Job Swapping Partially executed swapped-out processes Ready Queue CPU I/O Waiting queues I/O Terminate Swap out Swap in

23 Add Job Swapping to State Transition Diagram Running Blocked Ready Resource becomes available (move to ready queue) Create a process Terminate (call scheduler) Yield (call scheduler) Block for resource (call scheduler) Scheduler dispatch Swap out Swap in Swap

24 Think About Swapping Is swapping  Necessary  Desirable  Good  Ideal Things to consider  Performance  Complexity  Efficiency Moreover, what decides swapping versus paging? Is each appropriate somewhere?