Sie sind auf Seite 1von 20

PROCESS MANAGEMENT

PROCESS MANAGEMENT
A Process is an execution of a Program.
Running Instance of a Program is called a process.

A Program is actually a set of executable statements written in specific format that


the computer can use directly to execute the instructions.
We casually/generally use program term to refer to a file containing high level/middle level language
code.

An OS contains a large number of processes at any time. (Try ps command)


Process Management concerns

Creating Processes
Fulfilling their resource requirements
Scheduling them for use of a CPU
Implement Process Synchronization to control their interaction
Avoid Deadlock so that they do not wait for each other indefinitely
Terminating them when they complete their operation

Processes & Threads


Overview

Processes & Programs

What is a Process?
Relationships between Processes & Programs
Child Processes
Concurrency and Parallelism

Implementing Processes

Process States and State Transitions


Process Context and the Process Control Block
Context Save, Scheduling and Dispatching
Event Handling
Sharing, Communication and Synchronization between Processes
Signals

Threads
POSIX Threads
Kernel-Level, User-Level and Hybrid Threads

Case Studies of Processes & Threads

PROGRAM

PROCESSES AND

What is a Process?
A program is a passive entity that
does not perform any actions by
itself; it has to be executed if the
actions it calls for are to take place.
A process is an execution of a program. It
actually performs the actions specified in a
program.

The instructions, data and stack of


the program constitute its address
space.
A process comprises six components:
ID : Unique id assigned by the OS(in PCB/TCB)
Code: It is the code of the program(also called as text of a program)
Data: It is the data used in the execution of the program, including data from
files
Stack: stack contains parameters of functions and procedures called during
execution of the program, and their return addresses
Resources: resources is the set of resources allocated by the OS
CPU State: It is composed of contents of the PSW and the general-purpose

Programs

Processes and

Relationship between Processes and Programs


A program consists of a set of functions and procedures.
The OS doesnt know anything about the nature of a program, including
functions and procedures in its code.
It knows only what it is told through system calls. The rest is under the
control of the program.
The functions of a program may be separate processes, or they may constitute the code
part of a single process.

Two kinds of relationships can exist between processes and programs.

Programs

Processes and

Child Processes
The kernel initiates an execution of a program by creating a process for it. For lack
of a technical term for this process, we will call it the primary process for the
program execution.
The primary process may make system calls ,fork( ) or vfork( ), to create other
processes.
These processes become its child processes, and the primary process becomes their
parent.
A child process may itself create other processes, and so on.

The parentchild relationships between these processes can be represented in the


form of a process tree, which has the primary process as its root.
A child process may inherit some of the resources of its parent; it could obtain
additional resources during its operation through system calls.
Child processes in a Real-Time Application

????

Go through Example 5.1, OS by Dhamdhere

Programs

Child Processes

Processes and

Continue
Typically, a process creates one or more child processes and delegates some of
its work to each of them. It is called multitasking within an application.
It has three benefits summarized in the given table.

Processes and

Programs

Concurrency and Parallelism

Question No. 1 for Assignment 1


Write a note
Help: Topic 5.1.4, OS by Dhamdhere

IMPLEMENTING PROCESSES

In the operating systems view, a process is a unit of computational work. Hence


the kernels primary task is to control operation of processes to provide effective
utilization of the computer system.

Accordingly, the kernel allocates resources to a process, protects the process and
its resources from interference by other processes, and ensures that the process
gets to use the CPU until it completes its operation.

Fundamental functions of the kernel for controlling processes.


Context Save - Saving CPU state and information concerning resources of
the process whose operation is interrupted.
Event Handling - Analyzing the condition that led to an interrupt, or the request
by a process that led to a system call, and taking appropriate actions.
Scheduling - Selecting the process to be executed next on the CPU.
Dispatching - Setting up access to resources of the scheduled process and loading its
saved CPU state in the CPU to begin or resume its operation.

Implementing
Processes

Process States and State Transitions


An Operating system uses the notion of a process state to keep track of what a
process is doing at any moment. i.e. it describes the nature of current activity at
any moment.
The kernel uses process states to simplify its own functioning, so the number of
process states and their name many vary across Oss.
The Four fundament states of a process

Implementing
Processes

Process States and State Transitions


Continue

A state transition for a process P is a change in its state. A state transition is caused
by the occurrence of some event such as the start or end of an I/O operation. When
the event occurs, the kernel determines its inuence on activities in processes, and
accordingly changes the state of an affected process.
The figure diagrams the fundamental state transitions for a process. A new process
is put in the ready state after resources required by it have been allocated. It may
enter the running, blocked, and ready states a number of times as a result of
events.

Implementing
Processes

Process States and State Transitions


Continue

Implementing
Processes

Process States and State Transitions


Continue

Implementing
Processes

Process States and State Transitions


Exercise!!
Consider the time-sharing system, which uses a time slice of 10ms. It contains two
processes P1 and P2. P1 has a CPU burst of 15ms followed by an I/O operation that
lasts for 100ms, while P2 has a CPU burst of 30ms followed by an I/O operation that
lasts for 60ms. Execution of P2 and P1 is described in Figure. Draw a table for
process state transitions for P1 &P2.

Implementing
Processes

Process States and State Transitions


Solution!!

Solution

Question

Implementing
Processes

Process Context and the Process Control Block


The kernel allocates resources to a process and schedules it for use of the CPU.
Accordingly, the kernels view of a process consists of two parts:
Code, data, and stack of the process, and information concerning memory and
other resources, such as files, allocated to it.
Information concerning execution of a program, such as the process state, the
CPU state including the stack pointer, and some other items of information
described later.
These two parts of the kernels view are contained in the process context and the
process control block (PCB), respectively .

Implementing
Processes

Process Context and the Process Control Block


Continue...
Process Context consists of the following:
Address space of the process: The code, data, and stack components of
the process.
Memory allocation information: Information concerning memory areas
allocated to a process. This information is used by the memory
management unit (MMU) during operation of the process.
Status of file processing activities: Information about files being used,
such as current positions in the files.
Process interaction information: Information necessary to control
interaction of the process with other processes, e.g., ids of parent and
child processes, and interprocess messages sent to it that have not yet
been delivered to it.
Resource information: Information concerning resources allocated to the
process.
Miscellaneous information: Miscellaneous information needed for
operation of a process.

Implementing
Processes

Process Context and the Process Control Block


Continue...
The process control block (PCB) of a process contains three kinds of information
concerning the process:
Identification information such as the process id, id of its parent process,
and id of the user who created it.
Process state information such as its state, and the contents of the PSW
and the general-purpose registers (GPRs).
Information that is useful in controlling its operation, such as its priority,
and its interaction with other processes.
It also contains a pointer field that is used by the kernel to form
PCB lists for scheduling, e.g., a list of ready processes.
The priority and state information is used by the scheduler. It passes the id of the
selected process to the dispatcher.
For a process that is not in the running state, the PSW and GPRs fields together
contain the CPU state of the process when it last got blocked or was preempted.

Implementing
Processes

Process Context and the Process Control Block


Continue...

Implementing
Processes

Context Save, Scheduling, and Dispatching


The context save function performs housekeeping whenever an event occurs. It
saves the CPU state of the interrupted process in its PCB, and saves information
concerning its context.

The scheduling function uses the process state information from PCBs to select a
ready process for execution and passes its id to the dispatching function.

The dispatching function sets up the context of the selected process, changes its
state to running, and loads the saved CPU state from its PCB into the CPU.
Ex:
An OS contains two processes P1 and P2, with P2 having a higher priority than P1. Let P2
be blocked on an I/O operation and let P1 be running. The actions taken place when the
I/O completion event occurs for the I/O operation of P2.
?
?
?
?
?

Das könnte Ihnen auch gefallen