Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Process Management

What is a Process?

A process is basically a program in execution. The execution of a process must progress in a sequential fashion.

A process is defined as an entity which represents the basic unit of work to be implemented in the system.

To put it in simple terms, we write our computer programs in a text file and when we execute this program, it
becomes a process which performs all the tasks mentioned in the program.

When a program is loaded into the memory and it becomes a process, it can be divided into four sections ─ stack,
heap, text and data. The following image shows a simplified layout of a process inside main memory −

Figure 1. Process Architecture

1. Stack – The process stack contains the temporary data such as method/function parameters, return address
and local variables.
2. Heap – This is dynamically allocated memory to a process during its run time.
3. Text – This includes the current activity represented by the value of Program Counter and the contents of
the processor's registers.
4. Data – This section contains the global and static variables.

Program

A program is a piece of code which may be a single line or millions of lines. A computer program is usually written
by a computer programmer in a programming language. For example, here is a simple program written in C
programming language −
#include <stdio.h>
int main() {
printf("Hello, World! \n");
return 0;
}

A computer program is a collection of instructions that performs a specific task when executed by a computer. When
we compare a program with a process, we can conclude that a process is a dynamic instance of a computer program.

A part of a computer program that performs a well-defined task is known as an algorithm. A collection of computer
programs, libraries and related data are referred to as a software.

Three components of a process:


1. The executable program itself
2. The address space of the process
3. The execution context of the process

Process Scheduling

CPU Burst – the process is using the CPU to execute machine instructions
I/O Burst – the process is waiting for its I/O operation (writing to the disk) to finish

Process States

New state – A process is being created by the operating system.


Ready state – A process is ready to be executed by the CPU.
Running state – A process is being executed by the CPU.
Blocked state – A process stops executing because it is waiting for some event to happen.
Terminated state – A process has finished executing or has been aborted because of some reason.

Figure 2. Process State Diagram

FROM TO SAMPLE EVENT(S) CAUSING THE STATE


TRANSITION
New Ready when the newly created process is admitted into the system
Ready Running when the operating system assigns the CPU to the waiting
process
Running Blocked when the running process requested for an I/O operation and
therefore has to wait for the completion of its request
Running Ready when the running process is temporarily halted because of a
timeout event (recall that in multitasking, each process is given
a certain time limit to use the CPU) or because an interrupt
occurred forcing the CPU to stop the currently running process
and execute the ISR to respond to the interrupt request
Running Terminated when the running process completes its execution or is
intentionally halted by the operating system because of some
reason
Blocked Ready when the I/O operation of the process finishes or the event it is
waiting for occurs

Process Control Block

A Process Control Block is a data structure maintained by the Operating System for every process. The PCB is
identified by an integer process ID (PID). A PCB keeps all the information needed to keep track of a process.

Process descriptors – data structure wherein information about a process is stored


Figure 3. Process Control Block (PCB)

Typical information about a process that is stored in its PCB includes:

Process state: A process can be new, ready, running, waiting, etc.

Program counter: The program counter lets you know the address of the next instruction, which should be
executed for that process.

CPU registers: This component includes accumulators, index and general-purpose registers, and
information of condition code.

CPU scheduling information: This component includes a process priority, pointers for scheduling queues,
and various other scheduling parameters.

Accounting and business information: It includes the amount of CPU and time utilities like real time used,
job or process numbers, etc.

Memory-management information: This information includes the value of the base and limit registers, the
page, or segment tables. This depends on the memory system, which is used by the operating system.

I/O status information: This block includes a list of open files, the list of I/O devices that are allocated to
the process, etc.

The PCB is maintained for a process throughout its lifetime, and is deleted once the process terminates.

Process Operations

Major operations an operating system can perform on processes:

 Process creation
 Process termination
 Suspending a process
 Resuming a process

Context Switching - the operating system switches the CPU from one process to another

Concurrent Processing

Concurrency - execution of two or more independent processes at the same time

Cooperating processes - processes that share data with one another


Techniques that can be used by the operating system to facilitate IPC:

1. Signals – A system message sent from one process to another, not usually used to transfer data but instead
used to remotely command the partnered process.
2. Pipes – Pipe is a communication medium between two or more related or interrelated processes. It can be
either within one process or a communication between the child and the parent processes.
3. Message queuing – Typically implemented by the operating system, they allow multiple processes to read
and write to the message queue without being directly connected to each other.
4. Shared memory – Multiple processes are given access to the same block of memory which creates a
shared buffer for the processes to communicate with each other.

Figure 4. Shared Memory and Message Passing

Threads

Multithreaded process – a process that has several threads of execution

Processes and threads are similar in the following ways:

1. Like processes, each thread has its own ID number.


2. Like processes, each thread has its own state.
3. Like processes, each thread has its own set of internal CPU register values.
4. Like processes, each thread has its own scheduling priority.
5. Like processes, each thread has its own “process” control block which is called a thread control block
(TCB).
6. Like processes, the concept of context switching is also applicable to threads.
7. Child processes execute independently of each other and of the parent process that created them. Threads
also execute independently of each other and of the main thread that created them.

Processes and threads are different in the following ways:

1. Threads within a certain process share the same main memory space.
2. There is less information associated with each thread.
3. Threads belonging to the same process also share other resources allocated to the process.
4. A process cannot simply control another process unless there is a parent-child relationship between them.
5. Changes made to the parent process will not affect its children.

Advantages of using threads:

 It is easier to create a thread than to create a process.


 Context switching between threads is easier and faster than context switching between processes.
 Since threads share memory space, it is easier for them to communicate and share data with one another.
 Threads are easier to implement in terms of programming.

Disadvantages of using threads:

o Race condition may occur and cause data inconsistency.


o A malfunctioning thread can inadvertently terminate the process and all its threads.

A race condition occurs when two or more threads can access shared data and they try to change it at the same
time.

You might also like