Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

Similar documents
! The Process Control Block (PCB) " is included in the context,

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Chapter 4: Processes. Process Concept

Chapter 4: Processes

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

Process Concept. Chapter 4: Processes. Diagram of Process State. Process State. Process Control Block (PCB) Process Control Block (PCB)

Chapter 4: Processes

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

Chapter 4: Processes. Process Concept

The Big Picture So Far. Chapter 4: Processes

Diagram of Process State Process Control Block (PCB)

Processes. Operating System Concepts with Java. 4.1 Sana a University, Dr aimen

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

The Big Picture So Far. Chapter 4: Processes

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

Processes. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & Apps 1

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

Part Two - Process Management. Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts Essentials 8 th Edition

Chapter 3: Processes

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

Chapter 3: Process Concept

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Chapter 3: Processes

Chapter 3: Process Concept

Chapter 3: Process Concept

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

Chapter 3: Processes. Operating System Concepts 8th Edition,

Lecture 2 Process Management

Chapter 3: Process Concept

Processes. CSE 2431: Introduction to Operating Systems Reading: Chap. 3, [OSC]

Chapter 3: Processes. Operating System Concepts 9 th Edition

CHAPTER 3 - PROCESS CONCEPT

Chapter 3: Processes

Chapter 4: Processes

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss

Course: Operating Systems Instructor: M Umair. M Umair

Chapter 3: Processes. Operating System Concepts 9 th Edition

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

Chapter 4: Processes. Process Concept. Process State

CSC 539: Operating Systems Structure and Design. Spring 2006

Process Concept Process Scheduling Operations On Process Inter-Process Communication Communication in Client-Server Systems

Process Concept. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

CS370 Operating Systems

Chapter 3: Processes. Operating System Concepts 8th Edition

Process. Program Vs. process. During execution, the process may be in one of the following states

Chapter 3: Process Concept

Processes. CS3026 Operating Systems Lecture 05

Operating Systems. Figure: Process States. 1 P a g e

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors

ICS Principles of Operating Systems

Processes and Threads

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Killing Zombies, Working, Sleeping, and Spawning Children

CS420: Operating Systems. Interprocess Communication

Process. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Processes. Process Scheduling, Process Synchronization, and Deadlock will be discussed further in Chapters 5, 6, and 7, respectively.

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

2. PROCESS. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - XIV Virtual Memory - I. Louisiana State University.

Process! Process Creation / Termination! Process Transitions in" the Two-State Process Model! A Two-State Process Model!

CSI Module 2: Processes

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

Dept. Of Computer Science, Colorado State University

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

Frequently asked questions from the previous class survey

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

CSC Operating Systems Spring Lecture - XIV Virtual Memory - II. Tevfik Ko!ar. Louisiana State University. March 27 th, 2008.

Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Operating System Concepts Ch. 3: Processes

Processes. Process Concept

SMD149 - Operating Systems

Processes, PCB, Context Switch

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - VII CPU Scheduling - II. Louisiana State University

Roadmap. Multilevel Queue Scheduling. Multilevel Queue. Example of Multilevel Feedback Queue. Multilevel Feedback Queue. Tevfik Ko!

Principles of Operating Systems CS 446/ Processes. René Doursat

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

CHAPTER 2: PROCESS MANAGEMENT

CS Lecture 2! Processes! George Mason University! Fall 2010!

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Concurrent Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Processes. Operating System Concepts 8 th Edition

Page 1. Analogy: Problems: Operating Systems Lecture 7. Operating Systems Lecture 7

Process Scheduling Queues

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Process Description and Control. Chapter 3

UNIT - II PROCESS MANAGEMENT

Transcription:

CSC 4103 - Operating Systems Fall 2009 Lecture - III Processes Tevfik Ko!ar Louisiana State University September 1 st, 2009 1 Roadmap Processes Basic Concepts Process Creation Process Termination Context Switching Process Queues Process Scheduling Interprocess Communication 2

Process Concept a Process is a program in execution; user address space! A process image consists of three components 1. an executable program 2. the associated data needed by the program 3. the execution context of the process, which contains all information the O/S needs to manage the process (ID, state, CPU registers, stack, etc.) Stallings, W. (2004) Operating Systems: Internals and Design Principles (5th Edition). 3 Typical process image implementation Process Control Block! The Process Control Block (PCB) Typical process image implementation " is included in the context, along with the stack " is a snapshot that contains all necessary and sufficient data to restart a process where it left off (ID, state, CPU registers, etc.) " is one entry in the operating system s process table (array or linked list) context user address space process control block (PCB) stack data program code PCB 1 PCB 2 PCB 3... 4

Process Control Block! Example of process and PCB location in memory O/S process 1 process 2 context data program code process control block (PCB) stack data program code identification CPU state info control info stack data program code numeric identifier parent identifier user identifier etc. user-visible registers control & status registers program counter stack pointers, etc. schedulg & state info links to other proc s memory limits open files etc. stack Illustrative contents of a process image in (virtual) memory 5 Process State As a process executes, it changes state new: The process is being created ready: The process is waiting to be assigned to a processor running: Instructions are being executed waiting: The process is waiting for some event to occur terminated: The process has finished execution 6

Process Creation! Some events that lead to process creation (enter) all cases of process spawning " the system boots # when a system is initialized, several background processes or daemons are started (email, logon, etc.) " a user requests to run an application # by typing a command in the CLI shell or double-clicking in the GUI shell, the user can launch a new process " an existing process spawns a child process # for example, a server process (print, file) may create a new process for each request it handles # the init daemon waits for user login and spawns a shell " a batch system takes on the next job in line 7 Process Creation! Process creation by spawning A tree of processes on a typical UNIX system Silberschatz, A., Galvin, P. B. and Gagne. G. (2003) Operating Systems Concepts with Java (6th Edition). 8

... int main(...) {... if ((pid = fork()) == 0) { Process Creation Implementing a shell command interpreter by process spawning fprintf(stdout, "Child pid: %i\n", getpid()); err = execvp(command, arguments); fprintf(stderr, "Child error: %i\n", errno); exit(err); // create a process // execute child // process } else if (pid > 0) // we are in the { // parent process fprintf(stdout, "Parent pid: %i\n", getpid()); pid2 = waitpid(pid, &status, 0); // wait for child... // process }... } return 0; 9 1. Clone child process " pid = fork() Process Creation 2. Replace child s image " execve(name,...) O/S O/S O/S process 1 P1 context P1 data P1 program P1 context P1 data P1 program P1 context P1 data P1 program process 2! P1 context P1 data P1 program P2 context P2 data P2 program 10

Fork Example 1 #include! <stdio.h> main() {! int!ret_from_fork, mypid;! mypid = getpid();!!! /* who am i?! */! printf("before: my pid is %d\n", mypid); /* tell pid */! ret_from_fork = fork();! sleep(1);! printf("after: my fork returns pid : %d, said %d\n",!!! ret_from_fork, getpid()); } 11 Fork Example 2 #include! <stdio.h> main() {! fork();! fork();! fork();! printf("my pid is %d\n", getpid() ); } How many lines of output will this produce? 12

Process Termination! Some events that lead to process termination (exit) processtriggered O/S-triggered (following system call or preemption) hardware interrupttriggered software interrupttriggered " regular completion, with or without error code # the process voluntarily executes an exit(err) system call to indicate to the O/S that it has finished " fatal error (uncatchable or uncaught) # service errors: no memory left for allocation, I/O error, etc. # total time limit exceeded # arithmetic error, out-of-bounds memory access, etc. " killed by another process via the kernel # the process receives a SIGKILL signal # in some systems the parent takes down its children with it 13 Process Pause/Dispatch! Some events that lead to process pause / dispatch " I/O wait # a process invokes an I/O system call that blocks waiting for the I/O device: the O/S puts the process in Waiting mode and dispatches another process to the CPU " preemptive timeout # the process receives a timer interrupt and relinquishes O/S-triggered (following system call) hardware interrupttriggered (timer) control back to the O/S dispatcher: the O/S puts the process in Ready mode and dispatches another process to the CPU # not to be confused with total time limit exceeded, which leads to process termination 14

Process Context Switching When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process Context-switch time is overhead; the system does no useful work while switching Switching time is dependent on hardware support 15 CPU Switch From Process to Process 16

Process Context Switching! How does a full process switch happen, step by step? 1. save CPU context, including PC and registers (the only step needed in a simple mode switch) 2. update process state (to Ready, Blocked, etc.) and other related fields of the PCB 3. move the PCB to the appropriate queue 4. select another process for execution: this decision is made by the CPU scheduling algorithm of the O/S 5. update the PCB of the selected process (state = Running ) 6. update memory management structures 7. restore CPU context to the values contained in the new PCB 17 Process Context Switching! What events trigger the O/S to switch processes? " interrupts external, asynchronous events, independent of the currently executed process instructions # clock interrupt " O/S checks time and may block process traps # I/O interrupt " data has come, O/S may unblock process # memory fault " O/S may block process that must wait for a missing page in memory to be swapped in " exceptions internal, synchronous (but involuntary) events caused by instructions " O/S may terminate or recover process " system calls voluntary synchronous events calling a specific O/S service " after service completed, O/S may either resume or block the calling process, depending on I/O, priorities, etc. 18

Process Scheduling Queues Job queue set of all jobs in the system Ready queue set of all processes residing in main memory, ready and waiting to execute Device queues set of processes waiting for an I/O device Processes migrate among the various queues 19 Process Queues! The process table can be split into per-state queues " PCBs can be linked together if they contain a pointer field Structure of process lists or queues Stallings, W. (2004) Operating Systems: Internals and Design Principles (5th Edition). 20

Ready Queue And Various I/O Device Queues 21 Representation of Process Scheduling 22

Schedulers Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU 23 Schedulers (Cont.) Short-term scheduler is invoked very frequently (milliseconds) # (must be fast) Long-term scheduler is invoked very infrequently (seconds, minutes) # (may be slow) The long-term scheduler controls the degree of multiprogramming Processes can be described as either: I/O-bound process spends more time doing I/O than computations, many short CPU bursts CPU-bound process spends more time doing computations; few very long CPU bursts $long-term schedulers need to make careful decision 24

Addition of Medium Term Scheduling In time-sharing systems: remove processes from memory temporarily to reduce degree of multiprogramming. Later, these processes are resumed $ Swapping 25 Cooperating Processes Independent process cannot affect or be affected by the execution of another process Cooperating process can affect or be affected by the execution of another process Advantages of process cooperation Information sharing Computation speed-up Modularity Convenience Disadvantage Synchronization issues and race conditions 26

Interprocess Communication (IPC) Mechanism for processes to communicate and to synchronize their actions Shared Memory: by using the same address space and shared variables Message Passing: processes communicate with each other without resorting to shared variables 27 Communications Models a) Message Passing b) Shared Memory 28

Message Passing Message Passing facility provides two operations: send(message) message size fixed or variable receive(message) If P and Q wish to communicate, they need to: establish a communication link between them exchange messages via send/receive Two types of Message Passing direct communication indirect communication 29 Message Passing direct communication Processes must name each other explicitly: send (P, message) send a message to process P receive(q, message) receive a message from process Q Properties of communication link Links are established automatically A link is associated with exactly one pair of communicating processes Between each pair there exists exactly one link The link may be unidirectional, but is usually bi-directional Symmetrical vs Asymmetrical direct communication send (P, message) send a message to process P receive(id, message) receive a message from any process Disadvantage of both: limited modularity, hardcoded 30

Message Passing - indirect communication Messages are directed and received from mailboxes (also referred to as ports) Each mailbox has a unique id Processes can communicate only if they share a mailbox Primitives are defined as: send(a, message) send a message to mailbox A receive(a, message) receive a message from mailbox A 31 Indirect Communication (cont.) Operations create a new mailbox send and receive messages through mailbox destroy a mailbox Properties of communication link Link established only if processes share a common mailbox A link may be associated with many processes Each pair of processes may share several communication links Link may be unidirectional or bi-directional 32

Indirect Communication (cont.) Mailbox sharing P 1, P 2, and P 3 share mailbox A P 1, sends; P 2 and P 3 receive Who gets the message? Solutions Allow a link to be associated with at most two processes Allow only one process at a time to execute a receive operation Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was. 33 Synchronization Message passing may be either blocking or non-blocking Blocking is considered synchronous Blocking send has the sender block until the message is received Blocking receive has the receiver block until a message is available Non-blocking is considered asynchronous Non-blocking send has the sender send the message and continue Non-blocking receive has the receiver receive a valid message or null 34

Buffering Queue of messages attached to the link; implemented in one of three ways 1. Zero capacity 0 messages Sender must wait for receiver (rendezvous) 2. Bounded capacity finite length of n messages Sender must wait if link full 3. Unbounded capacity infinite length Sender never waits 35 Summary Processes Basic Concepts Process Creation Process Termination Context Switching Process Queues Process Scheduling Interprocess Communication Hmm.. Next Lecture: Threads Reading Assignment: Chapter 3 from Silberschatz. HW 1 will be out next class, due 1 week 36

Acknowledgements Operating Systems Concepts book and supplementary material by A. Silberschatz, P. Galvin and G. Gagne Operating Systems: Internals and Design Principles book and supplementary material by W. Stallings Modern Operating Systems book and supplementary material by A. Tanenbaum R. Doursat and M. Yuksel from UNR 37