Lesson 3 Process Management 1 Process Concept Process

  • Slides: 28
Download presentation
Lesson 3: Process Management 1

Lesson 3: Process Management 1

Process Concept • Process: A program in execution • Main purpose of Process: Maximize

Process Concept • Process: A program in execution • Main purpose of Process: Maximize processor utilization • An operating system executes a variety of programs: – Batch system – jobs – Time-shared systems – user programs or tasks • Terms job and process are used interchangeably.

Responsibility of Operating System in Process Management • Maximize processor utilization • Allocate resources

Responsibility of Operating System in Process Management • Maximize processor utilization • Allocate resources to processes • Support inter-process communication • Creation & termination processes • Scheduling of processes

Parts of Process • Text region – Stores the code that the processor executes

Parts of Process • Text region – Stores the code that the processor executes – Which may be shared with other processes that are executing the same program • Data region – Global variable Management • Stack region – Stores instructions and local variables for active procedure calls

Parts of Process • Program Counter – Current activity control • Heap – Containing

Parts of Process • Program Counter – Current activity control • Heap – Containing memory dynamically allocated during run time

The Process • Process – A program in execution. – An instance of a

The Process • 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.

The Process • Program is passive entity, process is active – Program becomes process

The Process • Program is passive entity, process is active – Program becomes process when executable file loaded into memory.

Process Control Block (PCB) • Process Control Block – Each process is represented in

Process Control Block (PCB) • Process Control Block – Each process is represented in operating system by Process Control Block.

Process Control Block (PCB) • Identifier – A unique identifier associated with this process,

Process Control Block (PCB) • Identifier – A unique identifier associated with this process, to distinguish it from all other processes. • State: – Current condition of process, either running, ready, etc. • Priority: – Priority level relative to other processes.

Process Control Block (PCB) • Program counter: – The address of the next instruction

Process Control Block (PCB) • Program counter: – The address of the next instruction in the program to be executed. • Memory pointers: – Includes pointers to the program code and data associated with this process, plus any memory blocks shared with other processes. • Context data: – These are data that are present in registers in the processor while the process is executing.

Process Control Block (PCB) • I/O status information: – Includes I/O requests, I/O devices

Process Control Block (PCB) • I/O status information: – Includes I/O requests, I/O devices (e. g. , tape drives) assigned to this process, etc. • Accounting information: – May include the amount of processor time, time limits, account numbers, and so on.

CPU Switch From Process to Process

CPU Switch From Process to Process

Process table • The OS maintains pointers to each process’s PCB in a system-wide

Process table • The OS maintains pointers to each process’s PCB in a system-wide or per-user process table – Maintain references to memory, I/O, and files, directly or indirectly – Allows for quick access to PCBs – When a process is terminated, the OS removes the process from the process table and frees all of the process’s resources.

Process table

Process table

Process Hierarchy • A process may spawn a new process – The creating process

Process Hierarchy • A process may spawn a new process – The creating process is called the parent process – The created process is called the child process – When a parent process is destroyed, operating systems typically respond in one of two ways: • Destroy all child processes of that parent • Allow child processes to proceed independently of their parents

Process Hierarchy

Process Hierarchy

Process State • As a process executes, it changes state – New: The process

Process State • As a process executes, it changes state – New: The process is being created – Running: Instructions are being executed • (only one process) – Waiting: The process is waiting for some event to occur – Ready: The process is waiting to be assigned to a processor – Terminated: The process has finished execution

Diagram of Process State

Diagram of Process State

Diagram of Process State

Diagram of Process State

Process Creation • Generally, process identified and managed via a process identifier (pid) •

Process Creation • Generally, process identified and managed via a process identifier (pid) • Resource sharing – Parent and children share all resources • Children share subset of parent’s resources • Execution – Parent and children can execute concurrently – Parent waits until children terminate • Process may be created for the purpose of: – – Interactive logon by user New Job Created by Operating System Spawned by existing process

Process Termination • Process executes last statement and asks the operating system to delete

Process Termination • Process executes last statement and asks the operating system to delete it (exit) – Process’ resources are de-allocated by operating system • Parent may terminate execution of children processes (abort) – Child has exceeded allocated resources – 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

Process Termination • Normal Completion – Completed successfully • Time Limit Exceed – If

Process Termination • Normal Completion – Completed successfully • Time Limit Exceed – If it runs longer • Memory unavailable – More memory requirements as provided by system • Bounds Violation – Access memory location which is not allowed

Process States Termination • Time Overrun – If process is waiting for longer period

Process States Termination • Time Overrun – If process is waiting for longer period of time without getting resources. • I/O Failure – If I/O is not responding • Privileged Instruction – Attempt to open reserved instructions for operating system • Operating system or Operator Intervention – Operator or Operating system may terminate process.

Process States Termination • Parent Request – When parent process request to terminate its

Process States Termination • Parent Request – When parent process request to terminate its child process. • Parent Termination – Some processes are depended on parent processes and terminate when parent process is terminated. • Protection Error – To use resource (Such as file) in an improper manner which is not allowed. • Arithmetic Error – Try for prohibited arithmetic (As. Division by zero)

Process Scheduling • Maximize CPU usage – Quickly switch processes onto CPU for time

Process Scheduling • Maximize CPU usage – Quickly switch processes onto CPU for time sharing • Process scheduler – Selects among available processes for next execution on CPU • Maintains scheduling queues of processes – 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

Context Switch • When CPU switches to another process, the system must save the

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 (environment) of a process represented in the PCB • Disadvantage: – Context-switch time is overhead; the system does no useful work while switching

Change of Process State save the context of the processor update the process control

Change of Process State save the context of the processor update the process control block of the process currently in the Running state move the process control block of this process to the appropriate queue select another process for execution restore the context of the processor to that which existed at the time the selected process was last switched out update memory management data structures update the process control block of the process selected 27

Schedulers • Long-term scheduler (or job scheduler) – selects which processes should be brought

Schedulers • Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue – Long-term scheduler is invoked very infrequently (seconds, minutes) (may be slow) • Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU – Sometimes the only scheduler in a system – Short-term scheduler is invoked very frequently (milliseconds) (must be fast)