0% found this document useful (0 votes)
40 views33 pages

Processs Management

Uploaded by

Marium naeem
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
0% found this document useful (0 votes)
40 views33 pages

Processs Management

Uploaded by

Marium naeem
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/ 33

Process

management
Operating system
Topics covered
• Processes
• PCB
• Context switching
• Process States
• Schedulers
• CPU and IO Bound
• Operation on Processes
• Spawning and Cascading
Processes
• A process can be thought of as a program in execution.
• A process will need certain resources—such as CPU time, memory, files, and I/O devices
— to accomplish its task.
• A program by itself is not a process.
• A program is a passive entity, such as a file containing a list of instructions stored on disk
(often called an executable file). In contrast, a process is an active entity, with a program
counter specifying the next instruction to execute and a set of associated resources.
Process • A process generally also includes the
process stack, which contains temporary

Structur data (such as function parameters, return


addresses, and local variables), and a data
section, which contains global variables. A
e process may also include a heap, which is
memory that is dynamically allocated
during process run time.
The
structure of
a process in
memory is:
Process State
As a process executes, it changes state.
A process may 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 (such as an I/O completion or reception
of a signal).
• Ready. The process is waiting to be assigned to a processor.
• Terminated. The process has finished execution.
Diagram of process state
Process Control Block

Each process is represented in the operating system by a process control block


(PCB)—also called a task control block.
Data structure maintained by the operating system or every process.
Keep track of information needed to track process.
It contains many pieces of information associated with a specific process…
PCB

• Process state - running, waiting, etc.


•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 the CPU.
o For a single-processor system, there will never be more than one running process.
o If there are more processes, the rest will have to wait until the CPU is free and can be
rescheduled.
Scheduling Queues
Job queue
o As processes enter the system, they are put into a job queue, which consists of all
processes in the system.
Ready queue
o The processes that are residing in main memory and are ready and waiting to execute are
kept on a list called the ready queue.
Device queue
o The list of processes waiting for a particular I/O device is called a device queue.
Cont...
A new process is initially put in the ready
queue. It waits there until it is selected for
execution, or dispatched. Once the process
is allocated the CPU and is executing, one of
several events could occur:
• The process could issue an I/O request and
then be placed in an I/O queue.
• The process could create a new child
process and wait for the child’s termination.
• The process could be removed forcibly
from the CPU, as a result of an interrupt, and
be put back in the ready queue
A process migrates among the various
scheduling queues throughout its lifetime.
Schedul
er
The selection process is carried
out by the appropriate scheduler.
Types of Scheduler
long-term scheduler, or job scheduler,
• selects processes from this pool and loads them into memory for
Process Scheduling execution.
short-term scheduler, or CPU scheduler,
• selects from among the processes that are ready to execute and
allocates the CPU to one of them.
Medium-term scheduler

• The key idea behind a medium-term scheduler is that sometimes it can be


advantageous to remove a process from memory (and from active
contention for the CPU) and thus reduce the degree of multiprogramming.
Later, the process can be reintroduced into memory, and its execution can be
continued where it left off. This scheme is called swapping.
Medium-term-scheduler
Context Switch
• 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 a context switch.
• When an interrupt occurs, the system needs to save the current context of
the process 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.
• interrupts 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 systems.
CPU – I/O Burst Cycle
• process execution consists of a cycle of CPU execution and I/O wait.
• Processes alternate between these two states.
• Process execution begins with a CPU burst. That is followed by an I/O burst, which is
followed by another CPU burst, then another I/O burst, and so on. Eventually, the final
CPU burst ends with a system request to terminate execution.
CPU bound

• CPU bound process execution depends only on the CPU. other components of
computer system are rarely used.
• Weather prediction, Artificial intelligence Applications are CPU-bound usually
require tons of calculations.
• Graphics operations are also CPU-bound. because calculations have to be
made to render graphics.
I/O bound

• I/O bound process execution depends only on the input-output devices.


• CPU is used less frequently or not at all.
• Word processing systems, Web applications are I/O bounds.
Operations on Processes

• The processes in most systems can execute concurrently, and they may be
created and deleted dynamically.
• Thus, these systems must provide a mechanism for process creation and
termination.
Process Creation

the creating process is Each of these new


During the course of
called a parent process, processes may in turn
execution, a process
and the new processes create other processes,
may create several new
are called the children forming a tree of
processes.
of that process. processes.
Process spawning
• Process spawning is a technique in which OS creates a child process
by the request of another process.
• When OS creates a child process by the request of the parent process.
process spawning VS Process
cascading
• process spawning involves the creation of a new process by an
existing process, allowing for multitasking and concurrent execution.
• Process cascading, on the other hand, ensures the termination of all
child processes when the parent process terminates, maintaining
system integrity. These concepts are fundamental to effectively
manage and control processes in operating systems.
Cont...

When a process creates a new process, two possibilities for execution exist:
1. The parent continues to execute concurrently with its children.
2. The parent waits until some or all of its children have terminated.
There are also two address-space possibilities for the new process:
1. The child process is a duplicate of the parent process (it has the same
program and data as the parent).
2. The child process has a new program loaded into it.
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, and I/O buffers—are deallocated by the operating system.
Cont..

Termination can occur in other circumstances as well.


• A process can cause the termination of another process via an
appropriate system call (for example, Terminate Process() in Windows).
• Usually, such a system call can be invoked only by the parent of the
process that is to be terminated.
• Otherwise, users could arbitrarily kill each other’s jobs
Cont..
A parent may terminate the execution of one of its children for a variety of reasons, such as
these:
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.)
The task assigned to the child is no longer required.
The parent is exiting, and the operating system does not allow a child to continue if its
parent terminates.
Cont...
• Some systems do not allow a child to exist if its parent has
terminated.
• In such systems, if a process terminates (either normally or
abnormally), then all its children must also be terminated. This
phenomenon, referred to as cascading termination, is normally
initiated by the operating system.
Thank you

You might also like