Chapter 3: Process Concept

Similar documents
Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

CHAPTER 3 - PROCESS CONCEPT

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

Chapter 3: Process Concept

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

Chapter 3: Processes. Operating System Concepts 9 th Edition

Chapter 3: Processes

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

Chapter 3: Processes

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

Chapter 4: Processes. Process Concept

Diagram of Process State Process Control Block (PCB)

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

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

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

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

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

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

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

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

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

The Big Picture So Far. Chapter 4: Processes

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

The Big Picture So Far. Chapter 4: Processes

Lecture 2 Process Management

Chapter 3: Processes. Operating System Concepts 8th Edition

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

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

Chapter 4: Processes. Process Concept

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

Chapter 4: Processes

CS370 Operating Systems

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

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

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 Concept Process Scheduling Operations On Process Inter-Process Communication Communication in Client-Server Systems

Chapter 3: Process Concept

Operating System Design

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

Chapter 4: Processes. Process Concept. Process State

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

CS307 Operating Systems Processes

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

Chapter 4: Processes

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

Course: Operating Systems Instructor: M Umair. M Umair

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

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

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

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

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

Processes and Threads

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

Chap 4, 5: Process. Dongkun Shin, SKKU

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

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

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

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

CHAPTER 2: PROCESS MANAGEMENT

Processes. Operating System Concepts 8 th Edition

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

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

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

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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

CS420: Operating Systems. Interprocess Communication

ICS Principles of Operating Systems

CS370 Operating Systems

CSC 539: Operating Systems Structure and Design. Spring 2006

Killing Zombies, Working, Sleeping, and Spawning Children

Operating Systems. Lecture 05

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

UNIT - II PROCESS MANAGEMENT

Processes. Process Concept

CS370 Operating Systems Midterm Review

Operating System Concepts Ch. 3: Processes

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

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

CSI Module 2: Processes

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

Chapter 3: Processes

Outline. Interprocess Communication. Interprocess Communication. Communication Models: Message Passing and shared Memory.

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

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

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

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

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line

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

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

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

Processes CHAPTER CHAPTER OBJECTIVES. 3.1 Process Concept

Transcription:

Chapter 3: Process Concept Chapter 3: Process Concept Process Concept Process Scheduling Operations on Processes Inter-Process Communication (IPC) Communication in Client-Server Systems Objectives 3.2 Process Concept To introduce the notion of a process -- a program in execution, which forms the basis of all computations To describe the various operations and features of processes, including scheduling, creation and termination, and communication An operating system executes a variety of programs: Textbook uses the terms job and process almost interchangeably Process a program in execution; process execution must progress in sequential fashion A process include: To explore interprocess communication using shared memory and message passing To describe communication in client-server systems A batch system executes jobs and a time-shared systems has user programs or tasks The program code, also called text section Current activity, represented by the program counter, processor registers Stack containing temporary data (such as function parameters, return addresses, local variables) Data section containing global variables Heap containing memory dynamically allocated during run time Program is a passive entity such as a file containing a list of instructions stored on disk (executable file), A process is an active entity, with a program counter specifying the next instruction to execute and a set of associated resources. A program becomes a process when an executable file is loaded into memory One program can be used by several processes Execution of program started via (1) GUI mouse clicks, (2) command line entry of its name Consider multiple users executing the same program 3.3 3.4

Process in Memory Process States and Diagram n As a process executes, it changes state, which is defined by the current activity Temporary data (function parameters, return addresses, and local variables) l New: The process is being created l Running: Instructions are being executed l Waiting: The process is waiting for some event to occur (such as I/O completion) l Ready: The process is waiting to be assigned to a processor (CPU) l Terminated: The process has finished execution Memory dynamically allocated during process run time Only one process at any instant Could have multiple processes Global variables Program code 3.5 Process Control Block (PCB) Each process is represented by a process control block in the operating system (also called task control block) Process state running, waiting, ready, halted, and so on Program counter location of instruction to next execute CPU registers contents of all process-centric registers CPU scheduling information - priorities, scheduling queue pointers Memory-management information memory allocated to the process Accounting information CPU used, clock time elapsed since start, time limits I/O status information I/O devices allocated to process, list of open files 3.7 3.6 CPU Switch From Process to Process 3.8

Threads Process Representation in Linux So far, process has a single thread of execution Represented by the C structure task_struct pid t pid; /* process identifier */ long state; /* state of the process */ unsigned int time slice /* scheduling information */ struct task struct *parent; /* this process s parent */ struct list head children; /* this process s children */ struct files struct *files; /* list of open files */ struct mm struct *mm; /* address space of this process */ This single thread of control allows a process to perform only one task at a time. If this is the case, a word-processor program cannot simultaneously type in characters and run the spell checker at the same time. Most modern OS allows a process to have multiple threads of execution, thus to perform more than one task at a time. This can best take advantage of the multicore systems, where multiple threads of one process can run in parallel. PCB has to be expanded to include information for each thread Multiple locations can execute at once Multiple program counters, one for each thread Chapter 4 discusses the details on Thread 3.9 main () { ; ; Stack A main Heap Program Maximize CPU use, quickly switch processes onto CPU for time sharing Process scheduler selects among available processes for next execution on CPU Maintains scheduling queues of processes A() { A() { Process Scheduling Process =? Program main () { 3.10 Process 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 among the various queues A process is more than just a program: A program is just part of the process state A process is less than a program: A program can be invoked or called by more than one process A program is static (line of codes stored) and a process has a life and is always in some state 3.11 3.12

Ready Queue And Various I/O Device Queues Representation of Process Scheduling 3.13 Queuing diagram represents queues, resources, flows Schedulers 3.14 Addition of Medium Term Scheduling 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 Medium-term scheduler can be added if degree of multiple programming needs to be decreased Remove a process from the memory, store on disk, bring back later in from disk to continue execution: swapping 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 scheduler strives for good process mix 3.15 3.16

Multitasking in Mobile Systems Context Switch Some systems / early systems allow only one process to run, others suspended Apple, beginning with ios4, provides a limited form of multitasking for user applications A single foreground application run concurrently with multiple background applications Single foreground process- currently on display and controlled via user interface Multiple background processes remain in memory, running, but not on the display Limited applications can run in background include single, finite-length task, receiving notification of events, specific long-running tasks like audio playback Constrained by battery life and memory usage Android runs foreground and background, with fewer limits There is no constraint on the types of applications that can run in background Background process uses a service to perform tasks, in which the service is a separate application component that runs on behalf of the background process Service can keep running even if background process is suspended Service has no user interface, small memory use, thus efficient 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 -> longer the context switch Typical speed is a few milliseconds Context-switch times are highly dependent on hardware support Some hardware provides multiple sets of registers per CPU (such as the SUN UltraSPARC) -> multiple contexts loaded at once Operating System Concepts 9 th Edition 3.17 Operating System Concepts 9 th Edition 3.18 Operations on Processes Process Creation The processes in most systems can execute concurrently, and they may be created and deleted dynamically. System must provide mechanisms for process creation, termination, and so on as detailed next A Parent process create 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 child share no resources Execution options Parent and children execute concurrently Parent waits until children terminate Operating System Concepts 9 th Edition 3.19 Operating System Concepts 9 th Edition 3.20

A Tree of Processes in Linux Process Creation (Cont.) init pid = 1 login pid = 8415 khelper pid = 6 bash pid = 8416 sshd pid = 3028 kthreadd pid = 2 pdflush pid = 200 Child duplicate of parent Child has a program loaded into it UNIX examples fork() system call creates new process, which duplicates the address space of the parent exec() system call used after a fork() to replace the process memory space with a new program sshd pid = 3610 tcsch pid = 4005 emacs pid = 9204 ps pid = 9298 Address space 3.21 What does it take to Create a Process? 3.22 fork(): create a new process Must construct new PCB Parent & Child: Inexpensive Must set up new page tables for address space More expensive Copy data from parent process? (Unix fork() ) Semantics of Unix fork() are that the child process gets a complete copy of the parent memory and I/O state Originally very expensive Copy I/O state (file handles, etc) Medium expense 3.23 n Different n PID n Running time n Running state n Return values from fork() n Duplicated n Address space n Global & local variables n Current working directory n Root directory n Process resources n Resource limits n etc 3.24

Return values of fork() The return value of the function is which discriminates the two processes of execution. Upon successful completion, fork() return 0 to the child process and return the process ID of the child process to the parent process. Otherwise, (pid_t)-1 is returned to the parent process, no child process is created, and errno is set to indicate the error. Return values of fork() n Successful child 0 fork() Child s PID parent n Not Successful child fork() -1 parent errno is set to indicate error 3.25 C Program Forking Separate Process 3.26 Creating a Separate Process via Windows API int main() { pid_t pid; /* fork another process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf(stderr, Fork Failed); exit(-1); else if (pid == 0) { /* child process */ execlp(/bin/ls, ls, NULL); else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf (Child Complete); exit(0); 3.27 3.28

Fork() and CreateProcess() Process Termination fork() has the child process inheriting the address space of its parent, while CreateProcess() requires loading a specified program into the address space of the child process at process creation fork() is passed no parameters, CreateProcess() expects no fewer than 10 parameters. In the example above, application mspaint.exe is loaded Process executes last statement and asks the operating system to delete 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()) Child has exceeded its usage of some of the resources that has been allocated Task assigned to child is no longer required If parent is exiting Some operating systems do not allow child to continue if its parent terminates All children terminated - cascading termination A parent process may wait for the termination of a child process by using wait() system call, returning the pid, so the parent process can tell which of its children has terminated. pid t pid; int status; pid = wait(&status); 3.29 If no parent waiting, then terminated process is a zombie. Once the parent calls wait(), the process identifier of the zombie process and its entry in the process table are released If parent terminated without calling wait(), the child processes are orphans. Linux and Unix assign the init process as the new process to orphan processes. Interprocess Communication Processes within a system may be independent or cooperating Cooperating process can affect or be affected by other processes, including sharing data Reasons for cooperating processes: Information sharing, for instance a shared file Computation speedup: subtasks of a task execute in parallel on multicore Modularity: system functions are divided into multiple processes or threads Convenience: users may work on multiple tasks in parallel Cooperating processes need an interprocess communication (IPC) mechanism that allow them to exchange data and information Two models of IPC, both common in operating systems Shared memory Message passing 3.31 Proc 3 Need communication mechanisms: Separate address spaces different processes Shared-Memory Mapping Proc 2 Multiple Processes Collaboration Proc 1 3.30 Accomplished by mapping addresses to shared-memory regions System calls such as read() and write() through memory This suffers from cache coherency issues in multicores (with multiple cache) Message Passing send() and receive() messages Can work across network Better performance in multicore systems. 3.32

Communications Models process A process A process B shared memory process B message queue m0 m1 m2 m3... mn Paradigm for cooperating processes, 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 kernel kernel (a) Producer-Consumer Problem (b) 3.33 Shared data #define BUFFER_SIZE 10 item next produced; typedef struct { while (true) { /* produce an item in next produced */... item; while (((in + 1) % BUFFER SIZE) == out) item buffer[buffer_size]; buffer[in] = next produced; int in = 0; in = (in + 1) % BUFFER SIZE; ; /* do nothing */ int out = 0; Bounded-Buffer Producer Bounded-Buffer Shared-Memory Solution 3.34 Solution is correct, but can only use BUFFER_SIZE-1 elements 3.35 3.36

Bounded Buffer Consumer item next consumed; while (true) { while (in == out) ; /* do nothing */ next consumed = buffer[out]; Interprocess Communication Message Passing Mechanism for processes to communicate and to synchronize their actions Message system processes communicate with each other without resorting to shared variables IPC facility provides atleast two operations: out = (out + 1) % BUFFER SIZE; If P and Q wish to communicate, they need to: /* consume the item in next consumed */ 3.37 How are links established? Can a link be associated with more than two processes? How many links can there be between every pair of communicating processes? What is the capacity of a link? Is the size of a message that the link can accommodate fixed or variable? Is a link unidirectional or bi-directional? 3.39 3.38 Direct Communication physical (e.g., shared memory, hardware bus) logical (e.g., direct or indirect, synchronous or asynchronous, automatic or explicit buffering) Implementation Questions establish a communication link between them exchange messages via send/receive Implementation of communication link send(message) message size fixed or variable receive(message) 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 A link is 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 3.40

Indirect Communication Messages are directed and received from mailboxes (also referred to as ports) Indirect Communication Operations Each mailbox has a unique id create a new mailbox Processes can communicate only if they share a mailbox send and receive messages through mailbox destroy a mailbox Properties of communication link A link is established only if processes share a common mailbox A link may be associated with more than two processes send(a, message) send a message to mailbox A Each pair of processes may share several communication links, i.e., mailboxes receive(a, message) receive a message from mailbox A Link may be unidirectional or bi-directional 3.41 Primitives are defined as: Indirect Communication Mailbox sharing P1, P2, and P3 share mailbox A P1, sends; P2 and P3 receive Who gets the message? Allow a link to be associated with at most two processes Allow at most one process at a time to execute a receive() operation Allow the system to select arbitrarily the receiver. The system may define an algorithm for selecting which process will receive the message (for example, round-robin), Sender is notified who the receiver was. 3.43 Message passing may be either blocking or non-blocking Blocking is considered synchronous Synchronization Different methods can be chosen: 3.42 Blocking send: The sending process is blocked until the message is received by the receiving process or by the mailbox Blocking receive: The receiver blocks until a message is available Non-blocking is considered asynchronous Non-blocking send: The sending process sends the message and resumes its operation Non-blocking receive: The receiver retrieves a valid message or null 3.44

Synchronization (Cont.) Different combinations possible If both send and receive are blocking, we have a rendezvous Buffering Queue of messages attached to the link (director indirect); implemented in one of three ways 1. Zero capacity 0 messages Sender must wait for receiver (rendezvous) Producer-consumer becomes trivial 2. Bounded capacity finite length of n messages Sender must wait if link full message next produced; 3. Unbounded capacity infinite length Sender never waits while (true) { /* produce an item in next produced */ send(next produced); message next consumed; while (true) { receive(next consumed); /* consume the item in next consumed */ 3.45 Sockets Communications in Client-Server Systems 3.46 Sockets A socket is defined as an endpoint for communication Pipes Concatenation of IP address and port a number included at start of message packet to differentiate network services on a host The socket 161.25.19.8:1625 refers to port 1625 on host IP address 161.25.19.8 Communication consists between a pair of sockets All ports below 1024 are well known, used for standard services Special IP address 127.0.0.1 (loopback) to refer to system on which process is running 3.47 3.48

Socket Communication 3.49 Pipes Acts as a conduit allowing two processes to communicate Pipes were one of the first IPC mechanisms in early UNIX systems Four Issues must be considered: Is communication unidirectional or bidirectional? In the case of two-way communication, is it half or full-duplex? Must there exist a relationship (such as parent-child) between the communicating processes? Can the pipes be used over a network or must reside on the same machine? Ordinary Pipes 3.50 Named Pipes Ordinary pipes allow communication in standard producer-consumer style- pipe(int fd[]) Producer writes to one end (the write-end of the pipe) fd[1] Named Pipes are more powerful than ordinary pipes Consumer reads from the other end (the read-end of the pipe) fd[0] Communication is bidirectional Ordinary pipes are therefore unidirectional, UNIX treats a pipe as a special type of file. No parent-child relationship is necessary between the communicating processes Require parent-child relationship between communicating processes on the same machine Several processes can use the named pipe for communication Provided on both UNIX and Windows systems Ordinary pipe ceases to exist after the processes have finished communicating and terminated Name pipes continue to exist after communicating processes have finished. Windows calls these anonymous pipes See Unix and Windows code samples in textbook 3.51 3.52

End of Chapter 3 Operating System Concepts 9 th Edition