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

Similar documents
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. Operating System Concepts 8th Edition,

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

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

Chapter 3: Processes

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

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

Chapter 4: Processes. Process Concept

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

Chapter 4: Processes

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State 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.

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

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

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

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

Chapter 3: Process Concept

Chapter 3: Process Concept

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

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

Diagram of Process State Process Control Block (PCB)

Chapter 3: Process Concept

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

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

CSC 539: Operating Systems Structure and Design. Spring 2006

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

CHAPTER 3 - PROCESS CONCEPT

Chapter 4: Processes. Process Concept

Part Two - Process Management. Chapter 3: Processes

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

Processes. Process Concept

Processes and Threads

Chapter 3: Processes

The Big Picture So Far. Chapter 4: Processes

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

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

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

Chapter 3: Processes. Operating System Concepts 8th Edition

Lecture 2 Process Management

Course: Operating Systems Instructor: M Umair. M Umair

The Big Picture So Far. Chapter 4: Processes

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

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100

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

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

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

Chapter 3: Process Concept

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

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

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

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

ICS Principles of Operating Systems

Operating System Concepts Ch. 3: Processes

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Processes COMPSCI 386

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

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

Processes. CS3026 Operating Systems Lecture 05

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

Operating Systems. Lecture 05

CHAPTER 2: PROCESS MANAGEMENT

Chapter 3: Process Concept

Chapter 3: Processes. Operating System Concepts 9 th Edition

CS370 Operating Systems

PROCESS CONCEPTS. Process Concept Relationship to a Program What is a Process? Process Lifecycle Process Management Inter-Process Communication 2.

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

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

Chapter 4: Processes. Process Concept. Process State

CS307 Operating Systems Processes

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

Mid Term from Feb-2005 to Nov 2012 CS604- Operating System

Process Description and Control

OPERATING SYSTEMS: Lesson 4: Process Scheduling

Chapter 4: Processes

Process Description and Control

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

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

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

(MCQZ-CS604 Operating Systems)

Operating System Design

Process! Process Creation / Termination! Process Transitions in" the Two-State Process Model! A Two-State Process Model!

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

SMD149 - Operating Systems

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

CSCE 313: Intro to Computer Systems

W4118 Operating Systems. Junfeng Yang

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

Operating Systems. II. Processes

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU

CSI Module 2: Processes

Agenda. Threads. Single and Multi-threaded Processes. What is Thread. CSCI 444/544 Operating Systems Fall 2008

3.1 Introduction. Computers perform operations concurrently

Transcription:

Processes Process Scheduling, Process Synchronization, and Deadlock will be discussed further in Chapters 5, 6, and 7, respectively. 1. Process Concept 1.1 What is a Process? A process is a program in execution. Processes exist in main memory. Stack Section Dynamic Data Section Static Data Section Code Section... PC Figure 4.1 Process in UNIX Contents in the processor s registers Code Section: Sequence of Instructions Static Data Section: e.g., global variables and arrays Dynamic Data Section: e.g., malloc() or calloc() calls Stack Section: e.g., local variables, function/procedure parameters, and return address PC (Program Counter): next instruction Note that a single text program on HDD can be loaded into several processes. For example, multi-users can execute mail program; the process of a program including a fork() system call will have child process at run time. 1.2 Type of Process A process may be Either OS process (e.g., system call) or User process Either I/O bound process or CPU bound process o I/O bound processes: Issue lots of I/O requests and little computation o CPU bound processes: Use CPU frequently and I/O infrequently Either Independent process or Cooperating process o Independent processes 1

Does not affect the execution of other processes Is not affected by other processes Does not share any data with other processes o Cooperative processes (e.g., producer/consumer example) Can affect the execution of other processes Can be affected by other processes Share data with other processes Either Foreground process or Background process o Foreground processes: Hold the terminal. Can receive input and return output from/to the user o Background processes Detached from the terminal it was started Runs without user interaction. The & sign will allow you to execute a process as a background process in UNIX. Run netscape and netscape & and observe the difference. 2. Process Scheduling Multiprogramming: Switch the CPU among processes so efficiently that the CPU is always running Time-sharing: Switch the CPU among processes so frequently that users can interact with their programs while they are running 2.1 Process State Interrupt (e.g., system call or device interrupt) New process Ready Running Terminated I/O or event completion I/O or event wait Waiting/ blocked Figure 4.2 Process State Diagram New process has ready state Ready state: The process is waiting to be assigned to the CPU Running state: An instruction of the process is being executed by the CPU 2

Waiting (blocked) state: The process is waiting for an event (e.g., an I/O completion, termination of a child process, a signal/message from another process). 2.2 PCB (Process Control Block) Each process is represented by a PCB in the OS. Process state PID (Process ID) PC (Program counter) Contents of the processor s registers Memory limits List of I/O devices allocated to the process List of open files etc. (e.g., priority of the process, amount of CPU time used, time limits, ) 2.3 Scheduling Queues Ready queue: a list of PCBs. Each PCB represents a ready process Several device queues: a list of PCBs. Each PCB represents a waiting process who is waiting for an I/O completion. o Examples: Tape#1 queue, Tape#2 queue, FDD queue, HDD queue, Printer queue, Terminal queue, etc Several waiting queues: a list of PCBs. Each PCB represents a waiting process who is waiting for an event (e.g., termination of a child process or reception of a signal/message) Note that a process exists in only one of the above queues at a time. 2.4 Long-term, Short-term, and Medium-term Schedulers Long-term scheduler: o Job pool: In multiprogrammed batch systems, there are often more processes submitted than can be executed immediately. These processes are spooled to the HDD (secondary storage). o Long-term scheduler selects processes from the job pool and fills the ready queue. Executes infrequently can takes more time to select a process Mainly used in Batch systems Controls the number of processes in main memory 1 1 When the number of processes in the main memory is always the same, the long-term scheduler will need to be invocated only when a process is terminated to select a process from the job pool. 3

Select a good mix of I/O bound processes and CPU bound processes to maximize both the I/O devices utilization and the CPU utilization Short-term scheduler (CPU scheduler): o Executes very frequently must be very fast o Select a process from the ready queue when the current process releases the CPU 2. Medium-term scheduler: o Swap in/out 3 partially executed processes to temporarily free up main memory by reducing the degree of multiprogramming (i.e., the number of processes in main memory). We may need this scheduler to improve the mix of I/O bound processes and CPU bound processes in main memory or to react to an increase in dynamic memory requests (e.g., malloc()). Swapped-out processes in the secondary storage New process Ready queue CPU Terminated Device queues Waiting queues Figure 4.3 Queueing-Diagram 2.5 Context Switching Occurs when the current process releases the CPU Procedure: o The current process releases the CPU voluntarily or involuntarily 2 Some scheduling techniques force the current process to release the CPU (i.e., Preemptive scheduling) 3 Swap out: remove a process from the main memory and store the image on HDD for later scheduling. Swap in: load a swapped-out process into the main memory and construct (or update) the PCB. 4

o OS updates the PCB of the current process with the current information (e.g., PC, contents of CPU registers, etc.) o Short-term scheduler selects the next process from the ready queue o OS load CPU registers with new data from the PCB of the next process to be executed o Start the instruction pointed to by the PC Frequently occurs and expensive decrease the system performance Some solutions o Multiple sets of registers o Special HW instruction (e.g., a single instruction to load or store all registers) o Threads whenever possible (e.g., A single process includes both producer and consumer Will be discussed in Chapter 6 in much more detail) 3. Process Creation and Process Termination Linux/UNIX System Calls fork, exec, execv, execve, wait, abort/exit(1)/exit(2)/exit(3)/kill, getpid, and getppid 3.1 Process Creation Parent Child Stack Stack (copy) Data Data (copy) Code Section (Shared read-only) Figure 4.4 The UNIX fork operation 4 If you use wait system call, the parent waits until some or all of its children terminate If you don t use wait system call, the parent continues to execute concurrently with its children If you use only fork call, the child process is a duplicate of the parent process 4 Goschinski, A. Distributed Operating Systems The Logical Design. Addison-Wesley, New York, 1992, p. 385. 5

If you use fork in the parent and execv in the child, the child process will have a program loaded into it. Note that a parent can call fork several times to create more children. Child process can also call fork a hierarchy of processes Parent Child Stack Stack of P2 Data Code Section Data of P2 Code of P2 Figure 4.5 After the child calls execv to load P2, the stack, data, and code of the child are overwritten. 3.2 Process Termination In UNIX, a process terminates when it calls exit (Normal termination) or abort (abnormal termination). exit terminates the calling process immediately. o Every open file will be closed. o All the resources will be freed. o The children of the process are inherited by process 1 (i.e., init process). Parent can terminate any of its children with kill(child PID, SIGKILL) operation for a variety of reasons. Note that a child can terminate its parent with kill(getppid(), SIGKILL) operation. 6

4. Threads Linux System Call clone and Linux/Unix System calls pthread_create/pthread_exit/pthread_join/pthread_detach/pthread_attr_init TASK: a set of peer threads. PEER THREADS: share code section, data section, and OS resources such as table of file descriptors and table of signal handlers. Each thread has its own stack and PC (see Figure 4.6) Good for the multi-processor systems in which the processors share main memory. USER THREAD: By calling special library functions, we can develop multiple threads of controls in our program that run concurrently (see Figure 4.6). o Fast switching: Switching among peer threads does not incur an interrupt to the Kernel (no short-term scheduling, no address space change, ). Only PC & stack-address switch among threads is required) Sometimes, we can modify multiple processes sharing some memory space to a task of multi-threads Faster, partially solve the context switch problem o Limitation (CPU scheduling units are not threads but tasks): When thread 1 of task 1 waits for I/O completion or a signal, the scheduler switches the CPU to another task. Thus, all peer threads in task 1 will be blocked because the task 1 releases the CPU and gets into a device (or waiting) queue. Scheduler allocates same amount of time to 100-thread task and 2- thread task. Motivation for Multi Thread Kernel 7

Stack 1 Stack 2 Stack 3 Data Thread 1 Thread 2 Thread 3 Code section that includes three concurrent functions (subroutines) Figure 4.6 An example of 3-thread task: a user program, which consists of three subsections that can run concurrently, can be a task that consists of three threads. (In a Linux, type man clone and read the man page.) Note, peer threads can read/write any other thread s stack. Multi-thread kernel: Kernel is a task of multiple threads. Therefore, o Fair scheduling: solve the limitations of user threads o Increased Kernel utilization: While one kernel thread is waiting for an I/O completion, the kernel can accept another request. Hybrid Approach: Both user threads and kernel threads are implemented (e.g., Solaris 2) 8

5. Inter-Process Communication (IPC) Linux/UNIX System Calls pipe/read/write, shmget/shmat/shmdt/shmctl, socket/socketpair 5.1 Introduction Cooperative processes: Why do we need them? o Information sharing o Computation speedup for multi-processor systems o Modularity o Convenience OS should provide Cooperative processes with communication mechanisms so that they can communicate with each other. (At least read-write or send-receive) Example of Cooperative processes: Producer-Consumer problem o Unbounded buffer or bounded buffer o Buffer can be provided by OS (i.e., message-passing) e.g., pipe() o Buffer can be programmed in the cooperative processes (i.e., shared memory) e.g., shmget() 5.2 Direct Communication Both sender and receiver must name each other. (Symmetric addressing) o Process Q: send (P, message) o Process P: receive (Q, message) Only the sender names the recipient. (Asymmetric addressing) o Process Q: send (P, message) o Process P: receive (id, message) Pros: provide some degree of protection Cons: Limited modularity (changing name of P) 5.3 Indirect Communication Messages are sent and received to/from ports (or mailboxes) Each port has a unique ID Process P: send (Port ID, message) Process Q: receive (Port ID, message) Mailbox can belongs to OS or programmed in cooperative processes 5.4 Buffering Port has Zero capacity: o Synchronization is necessary: Sender wait for receiver to send a message. When both of them are ready (i.e., Rendezvous), the sender can send a message. Port has Bounded capacity: o N messages can be stored in Port temporary. Note, N is the same as the port size. o Sender does not wait when the port is not full 9

o When the port is full, sender wait until one message in the port is consumed Port has Unbounded capacity: o Sender never has to wait for receiver 5.5 Issues with IPC These issues apply to both message passing and shared memory schemes Sender or receiver has been terminated and the other one is waiting for a message from the terminated one. Receiver has been terminated and the sender sent a message o Best solution: One of the error return value of the send/receive function is the sender/receiver has been terminated o So-So: OS terminates the other one. o Worst solution: OS does not care about it. Message was lost o Best: Its OS responsibility o So-so: OS detect it and tells the sender about it. o Worst: Its sender s responsibility. Message was damaged o Parity check, 10