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

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

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: Processes

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 4: Processes. Process Concept. Process State

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

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

Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Chapter 3: Processes. Operating System Concepts 9 th Edition

Processes and Threads

Killing Zombies, Working, Sleeping, and Spawning Children

Chapter 3: Processes. Operating System Concepts 8th 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

CHAPTER 3 - PROCESS CONCEPT

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

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

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: Processes. Operating System Concepts 9 th Edition

Chapter 3: Process Concept

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

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

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 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,

Operating System Design

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 Systems. Figure: Process States. 1 P a g e

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

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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

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

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

CS370 Operating Systems

Operating Systemss and Multicore Programming (1DT089)

Fall 2015 COMP Operating Systems. Lab #3

CS370 Operating Systems Midterm Review

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

Transcription:

Process Fundamentals Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne CSCI 315 Operating Systems Design 1

What Is A Process? A process is a program in execution. #include <stdio.h> int main(int argc, char*argv[]) { int v; printf( hello world\n ); scanf( %d, %d,&v); return 0; } Program test process is running %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

Process Concept 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 9/6/2013 CSCI 315 Operating Systems Design 3

Process States 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 4

Process State Transition Diagram created new admitted interrupt exit terminated ready running scheduler dispatch I/O or event completion I/O or event wait waiting 9/6/2013 CSCI 315 Operating Systems Design 5

Process Control Block (PCB) 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 6

A Sample Linux PCB http://www.eecs.harvard.edu/ harvard edu/~margo/cs161/ videos/sched.h.html http://www.tldp.org/ldp/tlk/ds/ds.htmltldp html Look for struct task_struct in the source code distribution ib i of Linux.

CPU Switching 9/6/2013 CSCI 315 Operating Systems Design 8

Process Scheduling 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. ec 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

Processes and OS Queues 9/6/2013 CSCI 315 Operating Systems Design 10

Process Scheduling ready queue CPU I/O I/O queue I/O request time slice expired child executes fork a child interrupt occurs wait for interrupt 9/6/2013 CSCI 315 Operating Systems Design 11

Schedulers Long term scheduler (or job scheduler) selects which processes should be brought into the ready queue Short term term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU 9/6/2013 CSCI 315 Operating Systems Design 12

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) g) Processes can be described as either: I/O bound b dprocess spends more time doing I/O than computations, tti many short CPU bursts CPU bound process spends more time doing computations; few very long CPU bursts 9/6/2013 CSCI 315 Operating Systems Design 13

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 14

Operations on Processes Creation Termination

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.) 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 forkto replace the process memory space with a new program. 9/6/2013 CSCI 315 Operating Systems Design 17

Process Tree (Linux Example) See example by running ps aef less

Create a Process in Linux #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@polariscode]$ d]$ gcc o create process fork.c [xmeng@polaris code]$./create process create process fork.c fork.c~ fork.o test process.c Child completed ltd [xmeng@polaris code]$ Screen recording http://www.eg.bucknell.edu/~cs315/fall13/code/process/fork.c

Process Termination Process executes last statement and asks the operating system to terminate t 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 ddallocated 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 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 (h (shared memory) A paradigm for cooperating gprocesses in which a producer process produces information that is consumed by a consumer process: unbounded bufferbuffer placesnopractical practical limit onthesize ofthebuffer buffer, bounded buffer assumes that there is a fixed buffer size. producer resource buffer consumer 9/6/2013 CSCI 315 Operating Systems Design 23

Bounded Buffer (shared memory solution) // define product structure struct product_t t { char name[32]; double value; }; #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 t * buffer; // function prototype for producers void insert(struct product_t * item); // function prototype for consumers struct product_t * remove(); } // buffer is initially empty 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

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_tt * 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 posix producer.c c http://www.eg.bucknell.edu/~cs315/fall13/code/ process/shm posix consumer.c 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/ 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. Blockingreceive 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

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