Chapter 3 Advanced Operating System

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

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Chapter 3 Process Description and Control
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
A. Frank - P. Weisberg Operating Systems Process Scheduling and Switching.
Introduction to Processes
6/9/2015B.Ramamurthy1 Process Description and Control B.Ramamurthy.
Process Description and Control
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Process Description and Control Chapter 3. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Page 1 Processes and Threads Chapter 2. Page 2 Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Review: Operating System Manages all system resources ALU Memory I/O Files Objectives: Security Efficiency Convenience.
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
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
CSSE Operating Systems
1 Chapter 4 Threads Threads: Resource ownership and execution.
1 Lecture 4: Processes Operating System Spring 2007 Chapter 4 of textbook.
Process Concept An operating system executes a variety of programs
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
Process Description and Control
Process Description and Control. Process concepts n Definitions – replaces task, job – program in execution – entity that can be assigned to and executed.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Process Description and Control
Operating System 3 PROCESS DESCRIPTION AND CONTROL.
CSNB224 – AAG 2007 Process Description and Control Chapter 3.
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 3 Process Description and Control
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Operating System 3 PROCESS DESCRIPTION AND CONTROL.
Chapter 3 Process Description and Control
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Requirements of an Operating System Fundamental Task: Process Management The Operating System must – Interleave the execution of multiple processes – Allocate.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z.
Threads G.Anuradha (Reference : William Stallings)
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
Politecnico di Milano © 2001 William Fornaciari Operating System Processes Lecturer: William Fornaciari Politecnico di Milano
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
1 Process Description and Control Chapter 3. 2 Requirements of an Operating System Interleave the execution of multiple processes to maximize processor.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Process Description and control G.Anuradha (Referred from william stallings and galvin 8 th edition)
CSNB224 – AAG 2007 Process Description and Control Chapter 3.
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.
Process Control Management Prepared by: Dhason Operating Systems.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Process Management Process Concept Why only the global variables?
Process Description and Control
Structure of Processes
Process & its States Lecture 5.
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Process Description and Control
Presentation transcript:

Chapter 3 Advanced Operating System Process and Thread Chapter 3 Advanced Operating System

Process A program in execution The entity that can be assigned to and executed on a processor Program code: which may be shared with other processes that are elements of a process Set of data

Process OS maintains the following for a process Executable program (.EXE, .DLL, etc) Data (variables, constant, buffer, …) User stack (local variables, function call) Process control block (PCB)

Process management Interleave the execution of several processes ... to maximize processor utilization while providing reasonable response time Allocate resources to processes Support inter-process communication

Dispatcher Program that moves the processor from one process to another Prevents a single process from monopolizing processor time. Every process should be able to use the processor for a fair amount of time

Two-state process model Not running Running Enter Dispatch Pause Exit

Two-state process model The operating system creates a new process Operating system creates PCB Operating system enters process into the system in the not running state The process exists is waiting to execute The currently running process will be interrupted The dispatcher will select some other process to run The former process moves from the running state to the not running state, and one of the other processes move to the running state

Process creation Submission of a batch job User logs on Create to provide a service such as printing Spawned by an existing process

Process creation Process spawning: When the operating system creates a process at the explicit request of another process When one process spawns another, the former is referred to as the parent process The spawned process is referred to as the child process

Process termination Batch job issues Halt instruction User logs off Process executes a service request to terminate Parent terminates so child processes terminate

Process termination Operating system intervention E.g. when deadlock occurs Error and fault conditions E.g. memory unavailable, protection error, arithmetic error, I/O failure, invalid instruction

Round-robin scheduling The queue is a first-in-first-out list The processor operates in round-robin fashion on the available process Each process in the queue is given a certain amount of time, in turn, to execute and then returned to the queue, unless blocked

Round-robin scheduling queue dispatch processor Each process is allowed to execute for at most a quantum. At timeout, process switching occurs.

Process is preempted when… In the following two cases, a process cannot continue running and must leave the processor. It is preempted. Timeout I/O, or wait for other events

Two states are not enough... Not-running: ready to execute blocked, e.g. waiting for I/O Dispatcher cannot just select the process that has been in the queue the longest (i.e. the one in queue front) because it may be blocked Running process Ready process Blocked process

Five-state Process Model New Exit Admit Release Running Ready Dispatch Time-out Blocked Event occurs Event wait

Five-state Model Running – being executed by the processor Ready – ready to execute Blocked – cannot execute until some event occurs New – created, but not yet admitted Exit – released

Blocked Queues Timeout Ready queue Processor Admit Dispatch Release Blocked queue/ Event queue Event occurs Event wait Running process Ready process Blocked process A separate queue holds the processes waiting for each event.

How process state changes (1/8) ready ready ready a := 1 b := a + 1 c := b + 1 read a file a := b - c c := c * b b := 0 a := 1 read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0 c := 0   

How process state changes (2/8) running ready ready a := 1 b := a + 1 c := b + 1 read a file a := b - c c := c * b b := 0 a := 1 read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0 c := 0      Timeout

How process state changes (3/8) ready running ready a := 1 b := a + 1 c := b + 1 read a file a := b - c c := c * b b := 0 a := 1 read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0 c := 0     Start I/O

How process state changes (4/8) ready blocked running a := 1 b := a + 1 c := b + 1 read a file a := b - c c := c * b b := 0 a := 1 read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0 c := 0  zz    Timeout

How process state changes (5/8) running blocked ready a := 1 b := a + 1 c := b + 1 read a file a := b - c c := c * b b := 0 a := 1 read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0 c := 0 zz   Start I/O

How process state changes (6/8) blocked blocked running a := 1 b := a + 1 c := b + 1 read a file a := b - c c := c * b b := 0 a := 1 read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0 c := 0 zz zz   Suppose the Green process finishes I/O

How process state changes (7/8) blocked ready running a := 1 b := a + 1 c := b + 1 read a file a := b - c c := c * b b := 0 a := 1 read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0 c := 0  zz  Timeout

How process state changes (8/8) blocked running ready a := 1 b := a + 1 c := b + 1 read a file a := b - c c := c * b b := 0 a := 1 read a file b := a + 1 c := b + 1 a := b - c c := c * b b := 0 a := 1 b := a + 1 c := b + 1 a := b - c c := c * b b := 0 c := 0  zz    Timeout

Suspend Processes Suspend – stop the execution of a process temporarily OS may suspend a process that causes a problem Interactive user request Timing: a process that executes periodically Swapping: sometimes OS may swap a blocked process to disk to free up more memory

Suspend states Two new states: Think about these… What’s the meaning of the two new states? Why not a single ‘suspend’ state? Why no ‘running, suspend’ state? Ready, suspend Blocked, suspend

Process state transition with suspend states New Suspend Admit Ready, suspend Blocked, suspend Event Occurs Activate Admit Dispatch Ready Running Exit Release Timeout Event Wait Event Occurs Blocked

An example of state transition Running The process starts an I/O operation Blocked The process is suspended while waiting for the I/O to finish Blocked suspend I/O is finished The process is activated before I/O is finished Ready suspend Blocked The process is activated afterwards I/O is finished Ready Ready

Process control block (PCB) Operating system creates and manages a process control block PCB is the key tool that enables the operating system to support multiple processes to provide the multiprocessing

Process Control Block PCB contains data that the OS needs to control the process PCB consists of Process identification Processor state information Process control information PCB Process identification pid:123 uid:tom Processor state info ax, bx, cx, eflags, pc, … cs, ds, ss, … Process control info …

Process Identification Process ID, a unique numeric identifier User identifier who is responsible for the job, or who runs the process used to determine what access rights the process has

Processor State Information Processor state: contents of processor registers, incl. Data registers Address registers: e.g. stack pointer Control and status registers Used to save and restore the processor state in process switching

Process Control Information Additional information needed by the operating system to control and coordinate the various active processes scheduling and state information data structuring interprocess communication process privileges memory management resource ownership and utilization

Process switching may happen at… Interrupt – an interruption request from hardware external to the CPU Trap – an error condition or exceptional condition associated with the current instruction Supervisor call – call of some special functions of the OS

Process switching may happen at… Interrupts Clock I/O: I/O completion, I/O error Traps illegal file access attempt memory fault Supervisor call file open, read a char synchronization primitive Timeout Event occurs Event wait

Process switching at Interrupt Timeout checked in clock interrupt (In OS that implements priority) When the I/O operation is finished for a blocked process, it is waken up. If its priority is higher than the running process, it will be dispatched. In case of I/O error (interrupt), the blocked process that is waiting for the I/O may be terminated.

Process switching at Trap In case error conditions caught as traps (memory fault, illegal access..), the process may be terminated, or blocked (or suspended) by the OS.

Process switching at Supervisor call A process may be blocked in executing supervisor call (for I/O, synchronization …)

Process Switching, Steps Consists of the following steps Save processor state (incl. program counter and other registers) in the PCB: processor state information Update the PCB with the new state and any accounting information Move the PCB to appropriate queue – ready, blocked 1 2 3

Process Switching, Steps (Continue) Select another process for execution Update the PCB of the process selected (new state and accounting information) Update memory-management data structures Restore context of the selected process restore the previous value of the program counter and other registers from the PCB 4 5 6 7

Steps in Process Switching (1/10) B0: mov AX, 8 B1: mov b, AX b A0: mov AX, a A1: inc AX A2: mov a, AX a AX PC state CPU PCB of process B PCB of process A Memory used by A Memory used by B ready ready xx 10 A0 B0 xx   2 99 a++ b = 8

Steps in Process Switching (2/10) B0: mov AX, 8 B1: mov b, AX b A0: mov AX, a A1: inc AX A2: mov a, AX a AX PC state CPU PCB of process B PCB of process A Memory used by A Memory used by B running ready 10 A0 B0 A0   2 99 Process A is dispatched. PCB of A is updated, and the processor state information is copied to the CPU.

Steps in Process Switching (3/10) B0: mov AX, 8 B1: mov b, AX b A0: mov AX, a A1: inc AX A2: mov a, AX a AX PC state CPU PCB of process B PCB of process A Memory used by A Memory used by B running ready 2 10 A0 B0 A1   2 99 After executing A0

Steps in Process Switching (4/10) B0: mov AX, 8 B1: mov b, AX b A0: mov AX, a A1: inc AX A2: mov a, AX a AX PC state CPU PCB of process B PCB of process A Memory used by A Memory used by B running ready 3 10 A0 B0 A2   2 99 After executing A1

Steps in Process Switching (5/10) B0: mov AX, 8 B1: mov b, AX b A0: mov AX, a A1: inc AX A2: mov a, AX a AX PC state CPU PCB of process B PCB of process A Memory used by A Memory used by B ready ready 3 3 10 A2 B0 A2   2 99 Timeout for Process A, which state changes from running to ready. PCB of A is updated, and the processor state information is copied from the CPU.

Steps in Process Switching (6/10) B0: mov AX, 8 B1: mov b, AX b A0: mov AX, a A1: inc AX A2: mov a, AX a AX PC state CPU PCB of process B PCB of process A Memory used by A Memory used by B ready running 10 3 10 A2 B0 B0   2 99 Process B is dispatched. PCB of B is updated, and the processor state information is copied to the CPU.

Steps in Process Switching (7/10) B0: mov AX, 8 B1: mov b, AX b A0: mov AX, a A1: inc AX A2: mov a, AX a AX PC state CPU PCB of process B PCB of process A Memory used by A Memory used by B ready running 8 3 10 A2 B0 B2   2 8 After executing B0 and B1

Steps in Process Switching (8/10) B0: mov AX, 8 B1: mov b, AX b A0: mov AX, a A1: inc AX A2: mov a, AX a AX PC state CPU PCB of process B PCB of process A Memory used by A Memory used by B ready ready 8 3 8 A2 B2 B2   2 8 Timeout for Process B, which state changes from running to ready. PCB of B is updated, and the processor state information is copied from the CPU.

Steps in Process Switching (9/10) B0: mov AX, 8 B1: mov b, AX b A0: mov AX, a A1: inc AX A2: mov a, AX a AX PC state CPU PCB of process B PCB of process A Memory used by A Memory used by B running ready 3 3 8 A2 B2 A2   2 8 Process A is dispatched. PCB of A is updated, and the processor state information is copied to the CPU.

Steps in Process Switching (10/10) B0: mov AX, 8 B1: mov b, AX b A0: mov AX, a A1: inc AX A2: mov a, AX a AX PC state CPU PCB of process B PCB of process A Memory used by A Memory used by B running ready 3 3 8 A2 B2 A3   3 8 After executing A2

Process Each process has Some resources allocated by OS, including memory to hold the process image A single thread of execution Only one instruction is being run at a time More threads of execution For each thread, only one instruction is being run at a time

Process v.s. Thread Process – Unit of resource ownership memory, files, I/O Thread – Unit of dispatching an execution path execution may be interleaved with other threads / processes A process has one or more threads

“More than one threads..” Sometimes, we want to have more than one threads of execution inside a single process. The multiple threads can share memory and other resources, while they can run ‘at the same time’.

OS Support for Threads and Processes one process multiple threads e.g. JVM one process one thread e.g. MS-DOS multiple processes one thread per process e.g. traditional Unix multiple processes multiple threads per process e.g. Windows 2000, Solaris, Apple OS X, BeOS, Linux, OS/390

Thread Has an execution state Has an execution stack Running, ready, blocked, suspend states … Has an execution stack Thread context is saved and restored in thread switching Read the following slides for how to change the steps of process switching to the steps of thread switching

Thread Has access to the memory and resources of its process Has some per-thread static storage for local variables

Single Threaded and Multithreaded Process Models In multithreaded process model, the OS keeps a Thread Control Block (TCB) for each thread. Much content of the original PCB is moved to TCB for each thread. Each thread has a TCB and a stack. Process Control Block stack Program Data Process image in a single-threaded process stack Thread Control Block stack Thread Control Block Process Control Block Program Data Process image in a multithreaded process

Thread Switching, Steps Consists of the following steps Save processor state (incl. program counter and other registers) in the TCB: processor state information Update the TCB with the new state and any accounting information Move the TCB to appropriate queue – ready, blocked 1 2 3

Thread Switching, Steps (Continue) Select another thread for execution Update the TCB of the thread selected (new state and accounting information) Update memory-management data structures Restore context of the selected thread restore the previous value of the program counter and other registers from the TCB 4 5 M 6

Thread Switching, Steps (simplified) Thread switching from thread A to thread B Save thread context of thread A: CPU  TCB A Update state in TCB A Move TCB A to appropriate queue Select another thread (thread B) Update state in TCB B Update memory-management data structures Restore thread context of thread B: TCB B  CPU 1 2 3 4 5 6

Benefits of Threads Less time to create / terminate a new thread than a process Less time to switch between two threads within the same process Communication among threads of the same process is easier

Benefits of Threads Less time to create / terminate a new thread than a process When the OS creates a process, it has to allocate memory for the process image, load the program and data, and initialize other resources When the OS creates a thread within an existing process, it does not need to initialize the process image. It only needs to set up a stack and TCB for the new thread.

Benefits of Threads Less time to switch between two threads within the same process The “update memory management data structure” step is only necessary in case of thread switching between different process.

Benefits of Threads Communication among threads of the same process is easier Threads within a process share memory and files Different processes have to communicate with the help of the kernel Kernel is the core of OS

Multiprocessing Refers to a computer system’s ability to support more than one process (program) at the same time. Multiprocessing operating system enable several programs to run concurrently. UNIX is one of the most widely used multiprocessing systems, but there are many others, including OS/2 for high-end PCs. Multiprocessing systems are much more complicated than single-process systems because the operating system must allocate resources to competing processes in a reasonable manner.

Multithreading The ability of an operating system to execute different parts of a program, called threads, simultaneously. The programmer must carefully design the program in such a way that all the threads can run at the same time without interfering with each other.