Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.

Slides:



Advertisements
Similar presentations
CSE 451: Operating Systems Winter 2007 Module 4 Processes Ed Lazowska Allen Center 570.
Advertisements

IT344 – Operating Systems Winter 2011, Dale Rowe.
Processes & Threads Today Next Time Process concept Process model
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
CSE 451: Operating Systems Winter 2006 Module 4 Processes Ed Lazowska Allen Center 570.
1 Processes Professor Jennifer Rexford
Processes CSCI 444/544 Operating Systems Fall 2008.
Chapter 3 Processes 1.
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.
CSSE Operating Systems
CSE451 Processes Spring 2001 Gary Kimura Lecture #4 April 2, 2001.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Processes April 5, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
CSE 451: Operating Systems Spring 2012 Module 4 Processes Ed Lazowska Allen Center 570.
Lecture Topics: 11/3 Address spaces Memory protection Creating a process –NT style –Unix style.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Introduction to Processes CS Intoduction to Operating Systems.
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.
Implementing Processes and Process Management Brian Bershad.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CSC 360- Instructor: K. Wu Processes. CSC 360- Instructor: K. Wu Agenda 1.What is a process? 2.Process states 3. PCB 4.Context switching 5.Process scheduling.
Processes Questions answered in this lecture: What is a process? How does the dispatcher context-switch between processes? How does the OS create a new.
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
CSE 451: Operating Systems Spring 2010 Module 4: Processes John Zahorjan Allen Center 534.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Processes.
Protection of System Resources
Lecture Topics: 11/1 Processes Process Management
CSE 451: Operating Systems Autumn 2013 Module 4 Processes
Chapter 3: Processes.
Process Realization In OS
Processes in Unix, Linux, and Windows
IT 344: Operating Systems Module 4 Processes
System Structure and Process Model
Processes in Unix, Linux, and Windows
More examples How many processes does this piece of code create?
Processes in Unix, Linux, and Windows
System Structure and Process Model
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Mid Term review CSC345.
Lecture Topics: 11/1 General Operating System Concepts Processes
Processes Hank Levy 1.
Processes and Process Management
Lecture 6: Multiprogramming and Context Switching
Chapter 3: Processes.
October 7, 2002 Gary Kimura Lecture #4 October 7, 2002
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
CSE 451: Operating Systems Autumn 2009 Module 4 Processes
IT 344: Operating Systems Winter 2008 Module 4 Processes
CSE 451: Operating Systems Winter 2007 Module 4 Processes
Processes in Unix and Windows
CS510 Operating System Foundations
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
CSE 451: Operating Systems Spring 2006 Module 4 Processes
Processes Hank Levy 1.
CSE 451: Operating Systems Autumn 2010 Module 4 Processes
Presentation transcript:

Multiprogramming CSE451 Andrew Whitaker

Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the CPU Transfer of control is called a context switch FirefoxWordjavacFirefoxWord time

The Process The process is an OS abstraction for a running program Process is associated with an address space Preview: Thread is a running program without its own address space code (text segment) static data (data segment) heap (dynamic allocated mem) stack (dynamic allocated mem) PC SP kernel space

How Do Processes Share the CPU? The OS maintains a per-process Process Control Block (PCB)  Which stores state for non-running processes On a context switch  Save state of the old process  Restore state of the new process CPU Old PCB New PCB

What’s in the PCB? The PCB is a data structure with many fields:  process ID (PID)  execution state (Ready, Running, Blocked)  program counter, stack pointer, registers  memory management info  UNIX username of owner  scheduling priority  accounting info In linux:  defined in task_struct ( include/linux/sched.h )  over 95 fields!!!

States of a process running ready blocked blocking I/O interrupt (unschedule) dispatch interrupt (I/O complete)

State queues The OS maintains a set of queues that represent the state of processes in the system  e.g., ready queue: all runnable processes  e.g., wait queue: processes blocked on some condition As a process changes state, its PCB is unlinked from one queue, and linked onto another

State queues There may be many wait queues, one for each type of wait (particular device, timer, message, …) head ptr tail ptr netscape pcbemacs pcbls pcb cat pcbnetscape pcb head ptr tail ptr Wait queue header Ready queue header

Walking Through a Context Switch Process A enters the kernel  Due to a system call, interrupt, or exception The kernel scheduler is invoked:  Is it time to context switch?  If so, which is the next process to run? Assembly routine exchanges hardware state  Save process A’s state to its PCB  Load process B’s state from its PCB (Process B now running) OS returns control to user mode

The Guts of Context Switching (x86) 1. define switch_to(prev,next,last) do { 2.unsigned long esi,edi; 3.asm volatile("pushl %ebp\n\t" 4. "movl %esp,%0\n\t /* save stackptr */ 5. "movl %5,%esp\n\t /* restore stackptr */ 6. "movl $1f,%1\n\t" /* save instr_ptr */ 7. "pushl %6\n\t" /* restore instr_ptr */ 8. "jmp __switch_to\n” /* Return to C */ 9. "1:\t"/* 1: is $1f*/ 10. "popl %ebp\n\t" 11. :"=m" (prev->thread.esp), /* %0 */ 12. "=m" (prev->thread.eip), /* %1 */ 13. "=a" (last), /* %2 */ 14. "=S" (esi),"=D" (edi) 15. :"m" (next->thread.esp), /* %5 */ 16. "m" (next->thread.eip), /* %6 */ 17. "2" (prev), "d" (next)); 18.} while (0)

UNIX Process API How do user programs interact with processes?  Fork: create a new process  Exec: run a program  Kill: destroy a process  Wait: wait for a process to exit

UNIX process creation Via the fork() system call Fork essentially clones the parent process  Child receives identical (but separate) address space  Child inherits open files from its parent The fork() system call “returns twice”  Returns the child’s PID to the parent  Returns 0 to the child

Fork example int value = 5; int main () { pid_t pid ; value = 7; pid = fork(); if (pid == 0) { /* Child */ value += 15; } else { /* Parent */ wait (NULL); /* Wait for child to terminate */ printf("PARENT: value = %d\n",value ); } What value is printed to the screen?

Exec vs. fork So how do we start a new program, instead of just forking the old program?  the exec() system call!  int exec(char *prog, char ** argv) exec()  stops the current process  loads program ‘prog’ into the address space  initializes hardware context, args for new program  places PCB onto ready queue  note: does not create a new process!

UNIX shells int main(int argc, char **argv) { while (1) { char *cmd = get_next_command(); int child_pid = fork(); if (child_pid == 0) { exec(cmd); panic(“exec failed!”); } else { waitpid(child_pid); }