Lecture 6: Multiprogramming and Context Switching

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Advertisements

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.
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Processes CSCI 444/544 Operating Systems Fall 2008.
Page 1 Processes and Threads Chapter 2. Page 2 Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential.
1 CS 333 Introduction to Operating Systems Class 2 – OS-Related Hardware & Software The Process Concept Jonathan Walpole Computer Science Portland State.
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
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
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.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
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,
Processes: program + execution state
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
More on UART Interrupts; System Calls Reference on Interrupt Identification Register(IIR) slide 17 of
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Operating Systems Processes 1.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
What is a Process ? A program in execution.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Processes and threads.
Process concept.
Protection of System Resources
CS 3305 System Calls Lecture 7.
Chapter 3: Processes.
Processes A process is a running program.
Processes in Unix, Linux, and Windows
Processes in Unix, Linux, and Windows
Lecture 5: Process Creation
Fork and Exec Unix Model
More examples How many processes does this piece of code create?
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.
Lecture Topics: 11/1 General Operating System Concepts Processes
Operating Systems Processes (Ch 4.1).
Processes Hank Levy 1.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Processes and Process Management
Jonathan Walpole Computer Science Portland State University
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
Section 2 Processes January 27rd, 2017 Taught by Joshua Don.
EECE.4810/EECE.5730 Operating Systems
Processes Hank Levy 1.
Chapter 3: Process Concept
Presentation transcript:

Lecture 6: Multiprogramming and Context Switching

Review: UNIX process memory layout Stack Heap Static data Text (program) Address space or core image

Review: Stack Frame arguments return address stack frame pointer Heap Static data Text (program) arguments return address stack frame pointer local variables To previous stack frame pointer To the point at which this function was called

Review: Creating a process via fork() Stack Heap Static data Text (program) fork() //return p Stack Heap Static data Text (program) fork() //return 0 The only way to create a new process is to use the fork system call. PC PC parent process child process process id = p

Review: Waiting Parent processes often wait for their child processes to end Parent processes do that via a wait() call pid_t wait(int * status); pid_t waitpid( pid_t pid, int * status,…);

Review: A stripped-down shell while (TRUE) { /* repeat forever */ type_prompt( ); /* display prompt */ read_command (command, parameters) /* input from terminal */ if (fork() != 0) { /* fork off child process */ /* Parent code */ waitpid( -1, &status, 0); /* wait for child to exit */ } else { /* Child code */ execve (command, parameters, 0); /* execute command */ }

Review: Loading a new image via exec() Stack Heap Static data Text (program) exec(prog, args) prog’s stack prog’s heap prog’s static data prog’s Text before after

Review: exec() example: #include <unistd.h> main() { printf(“executing ls\n”); execl(“/bin/ls”, “ls”, “l”, (char*)0); exit(1); }

More examples How many processes does this piece of code create? int main() { fork(); /*(Line 1)*/ fork(); /*(Line 2)*/ }

What is the output of this? int main() { int i; for (i=0; i<2; i++) { fork(); printf(“%d\n”,i); } return (0);

In this lecture Multiprogramming Process context switch

Why Multiprogramming? Imagine not having it Multiprogramming: Type in command in a shell Wait for result Can’t browse in the meanwhile! Multiprogramming: Many processes executing in parallel

Multiple Processes = Multiple Address Spaces User Kernel In this slide we view things from the point of view of the operating system, which has to deal with multiple address spaces, each belonging to a separate process. We normally think of a user process as executing user code. But when a process invokes kernel functions (by executing system calls), it switches into privileged mode and executes kernel code. Besides having its own stack in user mode, each process has a stack in the kernel for use when executing kernel code. There is also a common heap shared by all processes in the kernel, as well as the equivalents of data, BSS, and text. Copyright © 2002 Thomas W. Doeppner. All rights reserved.

Pseudoparallelism Multi-processor CPU Single processor CPU Real parallelism Single processor CPU Pseudoparallelism

The Process Model Multiprogramming 4 processes Conceptual model of 4 independent, sequential processes Only one program active at any instant

Implementation of Multiprogramming Context Switch Resources (CPU) taken away from one process and given to another Save the context of previous process and restore context of new process

Process Table Where is process table Process context Registers File management Others OS stores the context of a process in process table Each process has an entry in the process table Where is process table

When to Switch Context? When a process has reached its quota of time When a process waits for I/O When a previously started I/O has completed

Interrupt Driven Context Switch Interrupt occurs (timer or I/O) Each interrupt has its own service procedure (address given by interrupt vector) Save some context and then jump to interrupt service procedure Scheduler might context switch after the interrupt is serviced

Interrupt Implementation Skeleton of what lowest level of OS does when an interrupt occurs

Process States Possible process states running blocked ready

Summary Multiprogramming Context switching Process table Each entry stores context of a process

Will the following get speeded up with multiprogramming? Four compilations running in parallel A compilation and a text editor