Chapter 3: Processes.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Chapter 3 Process Description and Control
A. Frank - P. Weisberg Operating Systems Process Scheduling and Switching.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
CSCE 351: Operating System Kernels
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
CE Operating Systems Lecture 5 Processes. Overview of lecture In this lecture we will be looking at What is a process? Structure of a process Process.
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server.
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 3: Processes.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Processes. Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
11/13/20151 Processes ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original.
CS212: OPERATING SYSTEM Lecture 2: Process 1. Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 8 Processes II Read Ch.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Operating System Components) These components reflect the services made available by the O.S. Process Management Memory Management I/O Device Management.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Lecture 3 Process.
Processes and threads.
Chapter 3: Processes.
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
Operating System Concepts
Operating Systems (CS 340 D)
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Processes.
Processes Overview: Process Concept Process Scheduling
Chapter 3: Process Concept
Chapter 3: Processes Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Chapter 3: Processes.
Intro to Processes CSSE 332 Operating Systems
Operating Systems (CS 340 D)
Chapter 3: Process Concept
Applied Operating System Concepts
Chapter 3: Processes.
CGS 3763 Operating Systems Concepts Spring 2013
Chapter 4: Processes Process Concept Process Scheduling
Lecture 2: Processes Part 1
Recap OS manages and arbitrates resources
Operating Systems Lecture 6.
Process & its States Lecture 5.
Chapter 3: Processes.
Operating System Concepts
Process Description and Control
Chapter 3: Processes.
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Chapter 3: Processes Process Concept Process Scheduling
Chapter 3: Process Concept
Chapter 3 Processes.
Presentation transcript:

Chapter 3: Processes

Prerequisite Test Results 80% of students are familiar with C/C++ Total score is 120 Above 80: 0 70-79: 3 60-69: 6 50-59: 6 40-49: 6 Below 40: 11

Objectives To introduce the notion of a process To describe process scheduling, creation, termination, and communication To explore interprocess communication using shared memory and message passing To describe communication in client-server systems

OS Major Functions Interleave the execution of multiple processes, to maximize processor utilization while providing reasonable response time Allocate resources to processes Support interprocess communication and user creation of processes

Process A program in execution An instance of a program running on a computer The entity that can be assigned to and executed on a processor A unit of activity characterized by the execution of a sequence of instructions a current state an associated set of system resources

Process Concept Multiple parts The program code, also called text section Current activity context including program counter, processor registers Stack containing temporary data Function parameters, return addresses, local variables Data section containing global variables Heap containing memory dynamically allocated during run time

Process Concept (Cont.) Program is passive entity stored on disk (executable file), process is active Program becomes process when executable file loaded into memory How to execute a program? Execution of a program starts via GUI mouse click, command line entry of its name, etc. Can we have one program in several processes? Consider multiple users executing the same program on cse.unl.edu server

Process in Memory

Process Stack Parameter passing in a read procedure call: Figure (a) The stack before the call to read. (b) The stack while the called procedure is active.

Process State 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 e.g., a completion of an I/O operation or a semaphore signal from another process ready: The process is waiting to be assigned to a processor terminated: The process has finished execution

Diagram of Process State

How to describe a process? What elements are included in it? Process Elements (I) Identifier State Priority Program counter Memory pointers: to code and data How to describe a process? What elements are included in it?

Process Elements (II) Context data: value of CPU registers I/O status information Outstanding I/O requests Assigned I/O devices and used files Accounting information Amount of processor time & clock time used Time limits

Process Control Block (PCB) Each process is represented by a PCB Created and managed by the operating system Contains the process elements

Process Control Block Allows support for multiple processes

OS Control Tables Tables are constructed for each entity (i.e., process, resource) the operating system manages

Process Tables Manage processes A process is composed of program, data, heap, stack, and attributes ---- process image User Data The modifiable part of the user space, including data section and heap. User Program The program to be executed. Stack Each process has one or more last-in-first-out (LIFO) stacks associated with it. A stack is used to store parameters and returning addresses for procedure and system calls. Process Control Block Data needed by the OS to control the process

Process Location Where are the processes located? To manage and execute a process, at least a small portion of its image must be maintained in main memory OS must know the location of each page of each process image, achieved by process tables

Process Images

PCB: Process Control Information Data structuring: a process may be linked to other process in a queue, ring, or some other structure. For example, all ready processes for a particular priority level may be linked in a queue. A process may exhibit a parent-child (creator-created) relationship with another process. The process control block may contain pointers to other processes to support these structures.

Process Creation Assign a unique process identifier Allocate space for the process Initialize process control block Set up appropriate linkages Create or expand other data structures

When to Switch Process Clock interrupt I/O interrupt Memory fault process has executed for the maximum allowable time slice I/O interrupt Memory fault memory address is in disk so it must be brought into main memory

When to Switch Process Trap System Call error or exception occurred may cause process to be moved to Exit state System Call Inter-process communication I/O operation such as file open Lead to a transfer to an OS routine

How to Switch Process?

CPU Switch From Process to Process

Process (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 via a context switch Context of a process represented in the PCB Context-switch time is overhead; the system does no useful work while switching The more complex the OS and the PCB  the longer the context switch Time dependent on hardware support Some hardware provides multiple sets of registers per CPU  multiple contexts loaded at once

Process (Context) Switch Save context of processor including program counter and other registers Update the process control block of the process that is currently in the Running state Move process control block to appropriate queue – e.g., ready; blocked Select another process for execution Update the process control block of the process selected Restore context of the selected process Update memory-management data structures (page tables, TLB, etc.)

Execution of the OS Funtions Process Switch vs. Mode Switch

Execution of the Operating System Process-based operating system Implement the OS as a collection of system processes Process switch for OS service

Execution of the Operating System Execution Within User Processes Operating system software within context of a user process Mode switch for OS service

OS Executes in User Space Mode switch for OS service

Process vs. Mode Switch Save context of processor including program counter and other registers Update the process control block of the process that is currently in the Running state Move process control block to appropriate queue – ready; blocked; ready/suspend Select another process for execution Update the process control block of the process selected Restore context of the selected process Update memory-management data structures

Mode Switch Save context of processor including program counter and other registers Update the process control block of the running process Mode changes to kernel mode, finishes the OS routine Mode changes back, restore the context, and continue the running process in user mode A mode switch may occur without changing the state of the process that is currently in the Running state. Therefore, the context saving and subsequent restoration involve little overhead.

Process Scheduling (I) What does process scheduling do? What is the objective of doing process scheduling?

Process Scheduling (II) To maximize CPU use and for time sharing, quickly switch processes onto CPU Process scheduler selects among available processes for next execution on CPU OS maintains scheduling queues of processes Ready queues – 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

Process Scheduling (III) Three different categories of process scheduler Short-term scheduler Long-term scheduler Medium-term scheduler

Short-term Scheduler Short-term scheduler (or CPU scheduler or Dispatcher) – selects which process should be executed next and allocates CPU Sometimes the only scheduler in a system Short-term scheduler is invoked frequently (milliseconds)  (must be fast) Trace of the Process Sequence of instructions that execute for a process Dispatcher switches the processor from one process to another  Interleaving process traces

Example Execution

Trace of Process

Combined Trace of Process

Long-term Scheduler Long-term scheduler (or job scheduler) – selects which processes should be admitted (i.e., brought into ready queue) The long-term scheduler controls the (maximum) degree of multiprogramming Long-term scheduler is invoked infrequently (seconds, minutes)  (may be slow) 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 scheduler strives for good process mix

Addition of Medium Term Scheduling Medium-term scheduler can be added if (actual) degree of multiprogramming needs to change Remove process from memory, store on disk, bring back in from disk to continue execution: swapping Present in all systems with virtual memory (Chap 9)  Virtual Memory is controlled by the Medium term scheduler of an OS

Suspended Processes Processor is faster than I/O so all executable processes could be waiting for I/O, while there are some new processes waiting to be admitted Swap these processes to disk to free up more memory to admit new processes Blocked state becomes suspend state when swapped to disk Two new states Blocked/Suspend Ready/Suspend

Two Suspend States

Operations on Processes System must provide mechanisms for: process creation, process termination, and so on as detailed next

Process Creation Parent process creates children processes, which, in turn create other processes, forming a tree of processes Generally, process identified and managed via a process identifier (pid) Resource sharing options Parent and children share all resources Children share subset of parent’s resources Parent and children share no resources For example, rfork in FreeBSD permits fine-grained sharing of resources between parent and child processes Execution options Parent and children execute concurrently (e.g., fork) Parent waits until children terminate (e.g., vfork)

Process Creation (Cont.) Address space Child duplicate of parent UNIX example fork() system call creates new process

fork() Process creation in Unix could be made by means of the kernel system call, fork() When a process issues a fork request, the OS: Allocates a slot in the process table for the new process; Assigns a unique process ID to the child process; Makes a copy of the process image of the parent, with the exception of any shared memory; Increments counters for any files owned by the parent, to reflect that an additional process now also owns those files; Assigns the child process to the Ready to Run state; Returns the ID number of the child to the parent process, and a 0 value to the child process.

Process Creation (Cont.) Address space Child duplicate of parent Child has a program loaded into it UNIX examples fork() system call creates new process exec() system call used after a fork() to replace the process’ memory space with a new program

C Program Forking Separate Process

A Tree of Processes in Linux

Process Termination Process executes last statement and then asks the operating system to delete it using the exit() system call Returns status data from child to parent (via wait()) Process’ resources are deallocated by operating system Parent may terminate the execution of children processes using the abort() system call.

Process Termination Some operating systems do not allow child to exists if its parent has terminated. If a process terminates, then all its children must also be terminated cascading termination: all children, grandchildren, etc. are terminated. The termination is initiated by the operating system. The parent process may wait for termination of a child process by using the wait()system call. The call returns status information and the pid of the terminated process pid = wait(&status);

Process Termination If no parent waiting (did not invoke wait()), the terminated child process is a zombie, exit status kept in process table. Some operating systems allow child to exists if its parent has terminated. If parent terminated without invoking wait , process is an orphan, Linux and UNIX assign the init process as the new parent to orphaned processes, who invokes wait periodically to collect the exit status of any orphaned process and release its pid and process-table entry.

Multiprocess Application What are the reasons that we sometimes want to develop multiprocess applications?

Cooperating Processes Processes within a system may be independent or cooperating 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: video surveillance Computation speed-up: merge sort Modularity multiprocess browser; concurrent server system Convenience: a user’s multiple processes

Multiprocess Architecture – Chrome Browser Google Chrome Browser is multiprocess with 3 different types of processes: Browser process manages user interface, disk and network I/O Renderer process renders web pages, deals with HTML, Javascript. A new renderer created for each website opened Runs in sandbox restricting disk and network I/O, minimizing effect of security exploits Plug-in process for each type of plug-in

Example: Concurrent Server Request dispatched to a worker process Dispatcher process Server Worker process

Interprocess Communication Cooperating processes need interprocess communication (IPC) Two models of IPC Shared memory Message passing

Communications Models (a) Message Passing (b) Shared Memory

Producer-Consumer Problem Paradigm for cooperating processes: producer process produces information that is consumed by a consumer process

Interprocess Communication – Shared Memory An area of memory shared among the processes that wish to communicate The communication is under the control of the user processes, not the operating system Major issue is to provide mechanism that will allow the user processes to synchronize their actions when they access shared memory Synchronization is discussed in great detail in Chapter 5

Examples Linux Shared Memory Linux Mapped Memory shmget(), shmat(), shmdt() etc. Linux Mapped Memory shm_open(), mmap(), shm_unlink() etc.

Examples of IPC Systems - POSIX POSIX Shared Memory Process first creates shared memory segment shm_fd = shm_open(name, O CREAT | O RDWR, 0666); Also used to open an existing segment to share it Set the size of the object ftruncate(shm_fd, 4096); Now the process could write to the shared memory sprintf(shared memory, "Writing to shared memory");

IPC POSIX Producer

IPC POSIX Consumer

Interprocess Communication – Message Passing Mechanism for processes to communicate and to synchronize their actions IPC facility provides operations for sending and receiving messages The message size is either fixed or variable Self-read Chap 3.4 on message passing and understand how to solve the producer and consumer problem using message passing

Examples Linux IPC Pipes pipe() FIFOs (named pipes) makefifo()

Reading Assignment By this Wednesday, finish reading Chap 4