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

Similar documents
Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 3: Processes

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

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

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

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

Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

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

Operating System Design

Chap 4, 5: Process. Dongkun Shin, SKKU

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

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

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

Chapter 3: Processes

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

CHAPTER 3 - PROCESS CONCEPT

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

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

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

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

Killing Zombies, Working, Sleeping, and Spawning Children

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

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Chapter 3: Process Concept

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

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

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

Operating Systems. Lecture 05

Chapter 4: Processes. Process Concept

Chapter 4: Processes

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

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

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

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

Course: Operating Systems Instructor: M Umair. M Umair

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

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

Chapter 3: Process Concept

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

TDIU25: Operating Systems II. Processes, Threads and Scheduling

CSC 539: Operating Systems Structure and Design. Spring 2006

Diagram of Process State Process Control Block (PCB)

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

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

Processes and Threads

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

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

Start of Lecture on January 17, Chapter 3: Processes

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

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

Chapter 4: Processes

Part Two - Process Management. Chapter 3: Processes

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

W4118 Operating Systems. Junfeng Yang

Chapter 4: Processes. Process Concept

CHAPTER 2: PROCESS MANAGEMENT

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

CS370 Operating Systems

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Processes COMPSCI 386

The Big Picture So Far. Chapter 4: Processes

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

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

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

Processes. Process Concept

3.1 Introduction. Computers perform operations concurrently

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Processes. Operating System Concepts 8 th Edition

csci3411: Operating Systems

The Big Picture So Far. Chapter 4: Processes

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Lecture 2 Process Management

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.

Processes. Dr. Yingwu Zhu

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Computer Systems II. First Two Major Computer System Evolution Steps

CSCE 313: Intro to Computer Systems

Process and Its Image An operating system executes a variety of programs: A program that browses the Web A program that serves Web requests

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

CSI Module 2: Processes

CS307 Operating Systems Processes

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

Processes & Threads. Recap of the Last Class. Microkernel System Architecture. Layered Structure

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

Processes & Threads. Recap of the Last Class. Layered Structure. Virtual Machines. CS 256/456 Dept. of Computer Science, University of Rochester

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

Chapter 3: Processes. Operating System Concepts 8th Edition

Operating System Concepts Ch. 3: Processes

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

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

Announcement. Exercise #2 will be out today. Due date is next Monday

Transcription:

Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Slides based on the book Operating System Concepts, 9th Edition, Abraham Silberschatz, Peter B. Galvin and Greg Gagne, Wiley Chapter 3

Process Concept A process is the unit of work in most systems and can be thought of as a program in execution A process requires resources to accomplish its task: CPU time Memory Files I/O devices Resources can be allocated to a process either when it is created or while it is executing DCC-FCUP # 1

Process Concept Systems consist of a collection of processes: Kernel processes that execute system code User processes that execute user code Both kernel and user processes may execute concurrently The operating system is responsible for several important aspects of process management: Creation and deletion of processes Provision of mechanisms for allocating resources to processes Scheduling of processes Provision of mechanisms for synchronization, communication and deadlock handling for processes DCC-FCUP # 2

A process has multiple parts: Process Concept Text section, which contains the program code Data section, which contains global variables Heap, which contains memory dynamically allocated during process runtime Stack, which contains temporary data (such as function parameters, return addresses and local variables) Process control block, which includes the program counter and the CPU registers The text, data, heap and stack parts form the process s memory address-space DCC-FCUP # 3

Process Control Block (PCB) The operating system represents each process by a process control block (also called task control block), which contains many pieces of information associated with the process, including: Process state and process identification Program counter, the next instruction to be executed CPU registers, general purpose registers, index registers, stack pointers, etc Scheduling information, such as priorities, scheduling queue pointers, etc Memory information, the memory allocated to the process Accounting information, such as CPU used, clock time elapsed since start, time limits, etc I/O information, such as I/O devices allocated, list of open files, etc DCC-FCUP # 4

Operating System General Control Tables The OS maintains tables of information about the different entities that it is managing: Memory tables keep track of both physical and virtual memory being used I/O tables keep track if I/O devices are available or assigned to a process, if I/O operations are in progress and the memory locations being used as the source/destination of the I/O transfers File tables keep track of open files, their location and current status Process tables to manage processes DCC-FCUP # 5

Programs x Processes A program is a passive entity (often called an executable file) that contains a well-defined list of instructions A process is an active entity corresponding to an execution sequence of a program A program becomes a process when it is loaded into memory One program can be several processes Two processes associated with the same program are considered two separate execution sequences For instance, several users may run different copies of the mail program, or the same user may invoke many copies of the web browser program Each of these is a separate process and although the text sections are equivalent, the data, heap, and stack sections vary DCC-FCUP # 6

Process States As a process executes, it changes state accordingly to its current activity A process can be in one of the following states: New, the process is being created Running, instructions are being executed Waiting/Blocked, the process is waiting for some event to occur (such as an I/O operation or reception of a signal) Ready, the process is waiting to be assigned to a processor Terminated, the process has finished execution It is important to realize that many processes may be ready or waiting, but only one process at a time can be running on a processor DCC-FCUP # 7

Process States DCC-FCUP # 8

Transition Among States TI I/O TI HI TI: timer interrupt I/O: I/O system call HI: hardware interrupt DCC-FCUP # 9

Context Switch Context switch is the task of switching the CPU to another process Context switch requires saving the context of the current process to its PCB and loading the saved context for the new process from its PCB Context switch time is pure overhead, because the system does no useful work while switching A typical context switch speed is a few milliseconds Switching speed depends on the memory speed, on the number of registers that must be copied, and on the existence of special instructions The more complex the OS and the PCB, the longer the context switch Some machines support a special instruction that loads/stores all registers or provide multiple sets of registers per CPU (here, a context switch simply requires changing the pointer to the new register set) DCC-FCUP # 10

Context Switch DCC-FCUP # 11

Process Scheduling The goal of multiprogramming is to maximize CPU utilization, while the goal of multitasking is to switch the CPU among processes so frequently that users can interact with all programs while they are running To meet these goals, the process scheduler selects among available processes for next execution on CPU and for that, it maintains scheduling queues of processes: Job queue, set of all processes in the system Ready queue, set of processes waiting to execute Device queues, set of processes waiting for a specific I/O device DCC-FCUP # 12

Scheduling Queues DCC-FCUP # 13

Scheduling Queues PCBs move among the various queues as they change state Decisions about which order apply are scheduling decisions Many algorithms exist DCC-FCUP # 14

Process Creation During execution, a process may create several new processes The creating process is called a parent process and the new processes are called the children of that process Each new process may in turn create other processes, forming a tree of processes Most operating systems identify processes according to a unique process identifier (or pid), which is typically an integer number The pid provides a unique value for each process in the system, and it can be used as an index to access various attributes of a process within the kernel DCC-FCUP # 15

Tree of Processes i ni t pi d = 1 l ogi n pi d = 8415 kt hr e add pi d = 2 s s hd pi d = 3028 bas h pi d = 8416 khe l pe r pi d = 6 pdf l us h pi d = 200 s s hd pi d = 3610 ps pi d = 9298 e mac s pi d = 9204 t c s c h pi d = 4005 DCC-FCUP # 16

Parent/Children Creation Alternatives Resource sharing alternatives: Parent and children share all resources Children share subset of parent s resources Parent and child share no resources Execution alternatives: Parent and children execute concurrently Parent waits until some or all of its children have terminated Address space alternatives: Parent and child are duplicates (child starts with parent s program and data) The child process has a new program loaded into it DCC-FCUP # 17

What Does it Take to Create a Process? Assign process identifier and store new PCB Inexpensive Copy parent s I/O state (I/O devices allocated, list of open files, etc) Medium expensive Set up new memory tables for address-space More expensive Copy data from parent process Originally very expensive Much less expensive with copy-on-write DCC-FCUP # 18

Process Creation UNIX/Linux In UNIX/Linux, a new process is created by the fork() system call The new (child) process consists of a copy of the address space of the original (parent) process The return code for the fork() is zero for the child and the (nonzero) process identifier of the child is returned to the parent Both processes then continue execution concurrently at the instruction after the fork() This mechanism allows the parent process to communicate easily with its children DCC-FCUP # 19

Process Creation UNIX/Linux... // parent code before fork if ((pid = fork()) < 0) {... // fork failed } else if (pid = = 0) {... // child code after fork } else {... // parent code after fork }... // common code after fork DCC-FCUP # 20

Process Creation UNIX/Linux Typically after a fork(), one of the two processes (parent or child) invokes the exec() system call execl("/bin/ls","ls",null) The exec() system call replaces the process s memory space text, data, heap and stack parts with a brand new program from disk and starts executing the new program at its main function, destroying the previous image of the process However, since no new process is created, the calling process keeps its context (PCB) In this manner, parent and child are able to go in separate ways DCC-FCUP # 21

Process Termination A process terminates execution when it explicitly invokes the exit() system call or when it executes the last instruction (in this case, exit() is called implicitly by the return statement in main()) All process resources including physical and virtual memory, open files, and I/O buffers are then deallocated by the operating system A exit status value (typically an integer) is made available to the parent via the wait() system call A process may also terminate execution via its parent: Child has exceeded allocated resources Task assigned to child is no longer required The parent is exiting and the operating system does not allow a child to continue if its parent terminates (cascading termination) DCC-FCUP # 22

Process Termination If a process has terminated and no parent is waiting, then the terminated process is known as a zombie process Only when the parent calls wait(), the pid of the zombie process and its entry in the process table are released If a parent process terminates before their children, then such children, if any, are known as orphan processes UNIX/Linux address orphan processes by assigning the init process as the new parent to orphans processes The init process periodically invokes wait(), thereby allowing the orphan s process identifier and process table entry to be released DCC-FCUP # 23

Process Termination UNIX/Linux In UNIX/Linux, we can terminate a process by invoking the exit() system call, providing an exit status as a parameter exit(status) To wait for the termination of a child process and obtain its exit status, we can invoke the wait() system call, which also returns the pid of the terminated process so that the parent can tell which children has terminated pid = wait(&status) DCC-FCUP # 24

Forking a ls Command UNIX/Linux DCC-FCUP # 25

Interprocess Communication Processes within a system may be independent or cooperating: Independent process cannot affect or be affected by others execution Cooperating process can affect or be affected by others execution Main reasons for cooperating processes: Information sharing, concurrent access to the same piece of information Modularity, break the computation in subtasks that make more sense Speedup, execute concurrent subtasks in parallel To exchange data and information, cooperating processes need support for interprocess communication (IPC) mechanisms. There are two fundamental IPC models: Message passing Shared memory DCC-FCUP # 26

Message passing IPC Models Communication via sending/receiving messages Works across network Shared memory Communication occurs by simply reading/writing to shared memory Can lead to complex synchronization problems Typically, shared memory is faster than message passing Message passing mechanisms are typically implemented using systems calls and thus require a time-consuming task of kernel intervention With shared memory, system calls are required only to establish the shared memory regions and, after that, all accesses are treated as routine memory accesses and no kernel intervention is required DCC-FCUP # 27

IPC Models DCC-FCUP # 28

Pipes Pipes were one of the first IPC mechanisms in early UNIX systems and provide one of the simpler ways for processes to communicate Pipes allow communication in a standard producer consumer style: The producer writes to one end of the pipe (the write-end) The consumer reads from the other end (the read-end) Pipes are unidirectional, allowing only one-way communication If two-way communication is required, two pipes must be used, with each pipe sending data in a different direction Pipes can be constructed on the command line using the character: ls sort cat fich.txt grep xpto DCC-FCUP # 29

Pipes UNIX/Linux In UNIX/Linux, pipes are created using the pipe() system call int pipe(int fd[2]) The pipe() system call creates a new pipe and initializes fd[2] with the pipe file descriptors: fd[0] is the read-end of the pipe fd[1] is the write-end of the pipe UNIX/Linux systems treat pipes as a special type of file, which allows pipes to be accessed using ordinary read() and write() system calls DCC-FCUP # 30

Forking a Pipe A pipe cannot be accessed from outside the process that created it Typically, a parent process creates a pipe and uses it to communicate with a child process that it creates via fork() Since a pipe is a special type of file, the child inherits the pipe from its parent process DCC-FCUP # 31

Pipe from Parent to Child After a fork, we can decide the pipe s data flow direction For a pipe from parent to child, the parent closes the read-end of the pipe fd[0] and the child closes the write-end fd[1] Reading from an open pipe (i.e., at least one process has fd[1] open) blocks while it is empty DCC-FCUP # 32

Pipe Communication UNIX/Linux DCC-FCUP # 33