Process Management
Process Management
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
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..
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
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).
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)
3.The parent is exiting , and the operating system does not allow a
child to continue if its parent terminates – cascading termination
Contd..