100% found this document useful (1 vote)
478 views

Process Management

In this ppt, we discussed Process management component of an operating system (OS) that oversees the creation, execution, scheduling, and termination of processes.

Uploaded by

Elakkia U
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
478 views

Process Management

In this ppt, we discussed Process management component of an operating system (OS) that oversees the creation, execution, scheduling, and termination of processes.

Uploaded by

Elakkia U
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Process

Management
UNIT II
Process Management

 Introduction of process
 Various features of process
 Interprocess communication
Process Concepts

 processes vs Thread
 What is a process?
 A process can be a thought of as a program in execution
 What is thread?
 A thread is the unit of execution within a process.
Windows Task Manager
Process Explorer
Process Concepts

 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.
 A process is more than a program code which is called text section
 A process includes a stack which contains temporary data ( such as functions
parameters, return address , local variables)
 Data section – it contains global variables
 Heap – which is a memory that is dynamically allocated during process run time
Contd..
#include <stdio.h> int main()
{
#include <stdlib.h> // Local variable (Stored in Stack)
// Global variable (Stored in Data Segment -
int local_var = 5;
Initialized)
// Dynamically allocated variable (Stored in
int global_var = 10; Heap)
// Static variable (Stored in BSS Segment - int *heap_var = (int *)malloc(sizeof(int));
Uninitialized) *heap_var = 15;
static int static_var; // Perform addition
add(global_var, *heap_var);
void add(int a, int b) // Print memory locations
{ printf("Global Variable Address: %p\n",
// Local variable (Stored in Stack) (void*)&global_var);
int result = a + b; printf("Static Variable Address: %p\n",
printf("Addition Result: %d\n", (void*)&static_var);
printf("Local Variable Address: %p\n",
result); (void*)&local_var);
} printf("Heap Variable Address: %p\n",
(void*)heap_var);
printf("Function Address (Code Segment): %p\
n", (void*)&add); // Free allocated heap
memory free(heap_var); return 0; }
Process State

 As a process executes, it changes state.


 The state of a process is defined in part by the current activity of
that process.
 When a process executes, it passes through different states. These stages may
differ in different operating systems, and the names of these states are also not
standardized.
Each process can be in one of the
following states
NEW The process is being created

RUNNING Instructions are being executed

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
Process Control Block

 Each process is represent in the operating system by a Process


Control Block (PCB)- also called task control block.
 PCB -> we use to represent a particular process in the operating
system.
 A Process Control Block is a data structure maintained by the Operating System
for every process.
Process Control Block
 The PCB is identified by an integer process ID (PID). Unique ID
Process Control Block
 Process state – The current state of the process i.e., whether it
is ready, running, waiting, or whatever.
 Program counter – location of instruction to next execute
 CPU registers – contents of all process-centric registers
 CPU scheduling information- priorities, scheduling queue
pointers
 Memory-management information – memory allocated to
the process
 Accounting information – CPU used, clock time elapsed
since start, time limits
 I/O status information – I/O devices allocated to process, list
of open files
Process Scheduling
 The objective of multiprogramming is to have some process running at all times, to Maximize
CPU utilization.
 The objective of time sharing is to switch the CPU among processes so frequently that users can
interact with each program while it is running.
 To meet these objectives , the process scheduler selects an available process(possibly from a set
of several available processes) for program execution on CPU
 For a single-processor system, there will never be more than one running process.
 If there are more processes, the rest will have to wait until the CPU is free and can be rescheduled
scheduling queues
Ready Queue And Various I/O Device Queues 19

Ms.U.Elakkiya AP/IT
Schedulers
 Two types
 Long-term Scheduler
 Short-term scheduler
 Short-term scheduler (or CPU scheduler) – selects which process should be executed next and
allocates CPU
 Short-term scheduler is invoked frequently (milliseconds)  (must be fast)
 Long-term scheduler (or job scheduler) – selects which processes should be brought into the
ready queue
 Long-term scheduler is invoked infrequently (seconds, minutes)  (may be slow)
Contd..

 Most of the processes can be described as either:


 I/O-bound process – spends more time doing I/O than computations,
many short CPU bursts
 CPU-bound process – spends more time doing computations; few
very long CPU bursts
 Long-term scheduler strives for good process mix of I/O and CPU bound
Medium term scheduling
Context Switch

 What is context switch?

 When does it occur?

 What context switch do in an operating system?


Context switch

 Interrupt cause the operating system to change a CPU from its current task and to
run a kernel routine.
 Such operations happen frequently on general-purpose computers.
 When an interrupt occurs, the system needs to save the current context of the
process currently running on the CPU so that it can restore that context when its
processing is done, essentially suspending the process and then resuming it.
 The context is represented in the PCB of the process
CPU Switch From Process to
Process
Contd..

 Switching the CPU to another process requires performing a state save of the
current process and a state restore of a different process.
 This task is known as context switch
 Context-switch time is pure overhead, because the system does no useful work
while switching.
 It speed varies from machine to machine , depending on memory speed , the
number of registers that must be copied, and the existence of special instructions
 A typical speed is a few millisecconds.
Operations on Processes

 A process may create several new processes via a create-process


system call , during the course of execution.

 The creating process is called a parent process and the new


processes are called the children of that process

 Each of these new processes may in turn create other


processes , forming a tree of processes
Typical process tree in Linux
Contd..
 init process serves as the root parent process for all user process.
 Once the system booted, init process can create various user
process(web server , print , ssh)
 In the diagram can see 3 childrens for init process
 kthreadd process – create additional process that perform behalf of
kernel
 sshd - managing the clients that connect to the system by using
ssh(Secure shell)
 login – managing clients that directly log onto the system
 Command ps is used to list the process
Process Creation 30
 During the execution , a process may create a several new process.

Ms.U.Elakkiya AP/IT
Parent process – creating process
Children process – new process
 Generally, process identified and managed via a process identifier (pid) , which is
an integer.
 pid provides a unique value for each process in the system, and used as an index to
access various attributes of process within kernel
Contd..
When a process creates a new process , two possibilities exist in
terms of execution:
1. The parent continues to execute concurrently with its children
2.The parent waits until some or all of its children have terminated.
 When a process creates a child process , that child will need certain
resources(CPU time, memory, files, I/O devices) to accomplish its
task
 It may obtain its resources directly from OS or it may be
constrained to a subset of the resources of the parent process
 Theparent have to partition its resources among is children or share
some resources
Contd..
There are also two possibilities in terms of the address space of the new process.

 The child process is a duplicate of the parent process( it has the same program and data as a
parent).

 The child process has a new program loaded into it.


Contd..
 Process creation is achieved through the fork() system call.
 The newly created process is called the child process and the process that initiated it (or the
process when execution is started) is called the parent process
 After the fork() system call, now we have two processes - parent and child processes. How to
differentiate them? Very simple, it is through their return values.
Contd..
Contd..
 After creation of the child process, let us see the fork() system call details.
#include<sys/types.h>
#include<unistd.h>
pid_t fork(void);
 Creates the child process.
 After this call, there are two processes, the existing one is called the parent process and the
newly created one is called the child process.
Contd..
The fork() system call returns either of the three values −
 Negative value to indicate an error, i.e., unsuccessful in creating the child process.
 Returns a zero for child process.
 Returns a positive value for the parent process. This value is the process ID of the newly created
child process.
Let us consider a simple
program.
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
int main()
{
fork();
printf(“ called fork() system call”);
return 0;
}
Contd..

 UNIX examples
 system call creates new process
 exec() system call used after a fork() to replace the process’ memory space with a
new program
Process Termination

 Voluntary
 Normal exit
 Internal error (EX:If no input file find)
 Involuntary
 Fatal Error (Illegal memory access/ divide by zero)
 explicitly killed by another process
Operation on process –
process termination
 A process terminates when it finishes executing its final statement and asks the
operating system to delete it by using the exit() system call
 At that point , the process may return a status value( typically an integer) to its
parent process(via the wait() system call)
 All the resources of the process – including physical and virtual memory open
files, I/O buffers - are deallocated by the operating system
Contd..
Termination can occur in other circumstances as well:
 A process can cause the termination of another process via an appropriate system call
 Usually, such a system call can be invoked only by the parent that is to be terminated.
 Otherwise, the users could kill each other’s jobs
Contd..
A parent may terminate the execution of one of its children for a variety of reasons, such as these:

1.The child has exceeded its usage of some of the resources that it
has been allocated.(To determine whether this has occurred, the
parent must have a mechanism to inspect the state of its children)

2.The task assigned to the child is no longer required.

3.The parent is exiting , and the operating system does not allow a
child to continue if its parent terminates – cascading termination
Contd..

 A zombie process or defunct process is a dead process that has completed


execution but still has an entry in the process table, usually because of bugs
and coding errors.
 If the child process is dead but its parent process is alive,
the child process is declared zombie.
 An orphan process is a process that is still executing, but whose parent has died.
These process is adopted by init (Process ID 1). Orphan process will use all
resources which is required for its execution.

You might also like