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

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

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

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

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

Chapter 4: Processes. Process Concept

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

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

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

Chapter 4: Processes

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

Part Two - Process Management. Chapter 3: Processes

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

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

Chapter 3: Processes

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

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

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

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

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

Chapter 4: Processes

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

Chapter 4: Processes. Process Concept

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

Diagram of Process State Process Control Block (PCB)

The Big Picture So Far. Chapter 4: Processes

Chapter 3: Process Concept

The Big Picture So Far. Chapter 4: Processes

Chapter 3: Process Concept

Lecture 2 Process Management

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 3: Processes

Chapter 4: Processes. Process Concept. Process State

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

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

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

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

Chapter 3: Processes

Processes and Threads

Chapter 3: Processes. Operating System Concepts 8th Edition

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Killing Zombies, Working, Sleeping, and Spawning Children

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

Chapter 4: Processes

CS307 Operating Systems Processes

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

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

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

Processes. Process Concept

CHAPTER 2: PROCESS MANAGEMENT

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

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

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

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

CHAPTER 3 - PROCESS CONCEPT

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

Chapter 3: Process Concept

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

Processes. Operating System Concepts 8 th Edition

Operating Systems. Lecture 05

CS370 Operating Systems

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Process Concepts 8/21/2014. CS341: Operating System. Scheduling: Theoretical Analysis

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

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

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSC 539: Operating Systems Structure and Design. Spring 2006

CSCE 313: Intro to Computer Systems

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

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

Course: Operating Systems Instructor: M Umair. M Umair

Chap 4, 5: Process. Dongkun Shin, SKKU

Chapter 3: Processes

Process Concept Process in Memory Process State new running waiting ready terminated Diagram of Process State

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

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

ICS Principles of Operating Systems

Outlook. Process Concept Process Scheduling Operations on Processes. IPC Examples

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

Operating System Design

Processes COMPSCI 386

CSI Module 2: Processes

csci3411: Operating Systems

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

Processes and Threads

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

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

Operating Systems & Concurrency: Process Concepts

2/14/2012. Using a layered approach, the operating system is divided into N levels or layers. Also view as a stack of services

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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

Operating Systemss and Multicore Programming (1DT089)

Fall 2015 COMP Operating Systems. Lab #3

CS370 Operating Systems

CS370 Operating Systems Midterm Review

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

Transcription:

What Is A Process? A process is a program in execution. Process Fundamentals #include <stdio.h> int main(int argc, char*argv[]) { int v; printf( hello world\n ); scanf( %d, &v); return 0; Program test process is running Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne %gcc o test process test process.c %./test process & hello world %ps ef grep test process xmeng 22807 4288 0 10:08 pts/0 00:00:00./test process CSCI 315 Operating Systems Design 1 Process Concept Process States A process includes: program counter stack data section Process execution must progress in sequential fashion. Program Counter (PC) designates the next instruction to be executed program counter heap stack data code As a process executes, it changes state: new: The process is being created. running: Instructions are being executed. waiting: The process is waiting for some event to occur. ready: The process is waiting to be assigned to a processor. terminated: The process has finished execution. 9/6/2013 CSCI 315 Operating Systems Design 3 9/6/2013 CSCI 315 Operating Systems Design 4 Process State Transition Diagram Process Control Block (PCB) created new admitted interrupt ready scheduler dispatch I/O or event completion waiting running exit terminated I/O or event wait OS bookkeeping information associated with each process: Process state Program counter CPU registers CPU scheduling information Memory management information Accounting information I/O status information process id process state program counter registers memory limits list of open files 9/6/2013 CSCI 315 Operating Systems Design 5 9/6/2013 CSCI 315 Operating Systems Design 6 1

A Sample Linux PCB CPU Switching http://www.eecs.harvard.edu/~margo/cs161/ videos/sched.h.html http://www.tldp.org/ldp/tlk/ds/ds.html Look for struct task_struct in the source code distribution of Linux. 9/6/2013 CSCI 315 Operating Systems Design 8 Process Scheduling Queues Processes and OS Queues Job queue set of all processes 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 between the various queues. 9/6/2013 CSCI 315 Operating Systems Design 9 9/6/2013 CSCI 315 Operating Systems Design 10 Process Scheduling Schedulers ready queue I/O I/O queue I/O request CPU 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 time slice expired child executes fork a child interrupt occurs wait for interrupt 9/6/2013 CSCI 315 Operating Systems Design 11 9/6/2013 CSCI 315 Operating Systems Design 12 2

Schedulers Short term scheduler is invoked very frequently (milliseconds) (must be fast) Long term scheduler is invoked very infrequently (seconds, minutes) (may be slow; 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 Context Switch 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. What is in context? (Information in PCBs) Context switch time is overhead; the system does no useful work while switching. Time dependent on hardware support. 9/6/2013 CSCI 315 Operating Systems Design 13 9/6/2013 CSCI 315 Operating Systems Design 14 Creation Termination Operations on Processes Process Creation Parent process create children processes, which, in turn can create other processes, forming a tree of processes. Resource sharing: Parent and children share all resources, Children share subset of parent s resources, Parent and child share no resources. Execution: Parent and children execute concurrently, Parent may wait until children terminate. 9/6/2013 CSCI 315 Operating Systems Design 16 Process Creation (Cont.) Process Tree (Linux Example) Address space: Child has duplicate of parent s address space, or Child can have a program loaded onto it. UNIX examples: fork system call creates new process and returns with a pid (0 in child, > 0 in the parent), exec system call can be used after a fork to replace the process memory space with a new program. See example by running ps aef less 9/6/2013 CSCI 315 Operating Systems Design 17 3

Create a Process in Linux Process Termination #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]) { pid_t pid; if ((pid = fork()) < 0) { // error occured fprintf(stderr, "Fork failed\n"); return 1; else if (pid == 0) { // child process execlp("/bin/ls", "ls", NULL); else { // parent process wait(null); printf("child completed\n"); return 0; // or exit(0) [xmeng@polaris code]$ gcc o create process fork.c [xmeng@polaris code]$./create process create process fork.c fork.c~ fork.o test process.c Child completed [xmeng@polaris code]$ Screen recording Process executes last statement and asks the operating system to terminate it (exit) Output data from child to parent (via wait) Process resources are deallocated by operating system Parent may terminate execution of children processes (abort) if: Child has exceeded allocated resources, Task assigned to child is no longer required, If parent is exiting (some operating system do not allow child to continue if its parent terminates) All children terminated cascading termination http://www.eg.bucknell.edu/~cs315/fall13/code/process/fork.c 9/6/2013 CSCI 315 Operating Systems Design 20 Interprocess Communications (IPC) Shared memory Message passing Pipe Socket Cooperating Processes An independent process cannot affect or be affected by the execution of another process. A cooperating process can affect or be affected by the execution of another process. Cooperating processes have to communicate with each other! (Don t we?) Inter process communication (IPC) Shared memory: processes share a common area of memory for information Message passing: processes send messages to each other through message delivery system 9/6/2013 CSCI 315 Operating Systems Design 22 Producer Consumer Problem (shared memory) A paradigm for cooperating processes in which a producer process produces information that is consumed by a consumer process: unbounded buffer places no practical limit on the size of the buffer, bounded buffer assumes that there is a fixed buffer size. producer resource buffer consumer 9/6/2013 CSCI 315 Operating Systems Design 23 // define product structure struct product_t { char name[32]; double value; ; // function prototype for producers void insert(struct product_t * item); // function prototype for consumers struct product_t * remove(); Bounded Buffer (shared memory solution) #include buffer.h #define BFSIZE 5 int main(int argc, char* argv[]) { int count; // number of items in the buffer int in; // index to the next free position int out; // index to the next full position struct product_t * buffer; // buffer is initially empty py count = 0; in = 0; out = 0; buffer = (struct product_t *)malloc(bfsize* sizeof(struct product_t)); while (true) { producer(); // these two would run in parallel consumer(); buffer.h buffer.c 9/6/2013 CSCI 315 Operating Systems Design 24 4

void producer() { struct product_t * item; while (true) { item = makeitem(); insert(item); Bounded Buffer (shared memory solution for producer) public void insert(struct product_t * item) { while (count == BFSIZE); // do nothing -- no free buffers // now we have a free slot, add an item to the buffer ++count; buffer[in] = item; in = (in + 1) % BFSIZE; 9/6/2013 CSCI 315 Operating Systems Design 25 struct product_t * consumer() { struct product_t * item; while (true) { item = remove(); Bounded Buffer (shared memory solution for consumer) struct product_t * remove() { struct product_t * item; while (count == 0); // do nothing -- nothing to consume // remove an item from the buffer --count; item = buffer[out]; out = (out + 1) % BUFFER SIZE; return item; 9/6/2013 CSCI 315 Operating Systems Design 26 Synchronization Between Consumer and Producer In the above solution, we used a busy waiting strategy while (count == 0); // for consumer while (count == BFSIZE); // for producer Issues? (we will tackle them at a later time) What if both the consumer and the producer updates the count at the exact same moment? Busy waiting is less efficient in using resources (CPU time), better mechanism has to be developed. Posix Shared Memory Solution See the code example at http://www.eg.bucknell.edu/~cs315/fall13/code/ process/shm posix producer.c http://www.eg.bucknell.edu/ edu/~cs315/fall13/code/ process/shm posix consumer.c Message Passing Processes must use communications facility provided by the OS, e.g., socket(), or pipe() See the code example for Unix pipe at http://www.eg.bucknell.edu/fall13/code/process/ /F ll13/ d / / pipe.c 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. 9/6/2013 CSCI 315 Operating Systems Design 30 5

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. 9/6/2013 CSCI 315 Operating Systems Design 31 6