Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
78 views

Operating System Processes and CPU Scheduling

The document discusses processes and CPU scheduling. It defines a process as a program in execution. It describes the process life cycle including new, ready, running, waiting, and terminated states. It discusses process architecture including the stack, heap, text, and data sections. It also describes the process control block (PCB) which contains process information used by the operating system. It then discusses CPU scheduling, queues, and different types of schedulers for long term, short term, and medium term scheduling. Context switching and its role in multitasking is also summarized.

Uploaded by

Radhika Badbade
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Operating System Processes and CPU Scheduling

The document discusses processes and CPU scheduling. It defines a process as a program in execution. It describes the process life cycle including new, ready, running, waiting, and terminated states. It discusses process architecture including the stack, heap, text, and data sections. It also describes the process control block (PCB) which contains process information used by the operating system. It then discusses CPU scheduling, queues, and different types of schedulers for long term, short term, and medium term scheduling. Context switching and its role in multitasking is also summarized.

Uploaded by

Radhika Badbade
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Unit 02

Processes and CPU Scheduling


Process
• A program in execution is called a process.
• A Program does nothing unless its instructions are executed by
a CPU.
• Program is a passive entity.
• process is an active entity.
• In order to accomplish its task, process needs the computer
resources(CPU,memory,IO).
• There may exist more than one process in the system which
may require the same resource at the same time.
• Therefore, the operating system has to manage all the
processes and the resources in a convenient and efficient way.
Process
• Some resources may need to be executed by one
process at one time to maintain the consistency
otherwise the system can become inconsistent and
deadlock may occur.
• The operating system is responsible for Process
Management……………
• Creating and deleting both user and system processes.
• Scheduling processes and threads on the CPUs.
• Suspending and resuming processes.
• Providing mechanisms for process synchronization.
• Providing mechanisms for process communication.
Process Architecture
Process Architecture

• Stack
contains the temporary data such as method/function
parameters, return address and local variables.
• Heap
This is dynamically allocated memory to a process during its
run time.
• Text
This includes the value of Program Counter and the
contents of the processor's registers.
• Data
This section contains the global and static variables.
Process Life Cycle
• New: This is the initial state when a process is first
started/created.
• Ready: In a ready state, the process should be
loaded into the primary memory, which is ready for
execution.
• Waiting: The process is waiting for the allocation of
CPU time and other resources for execution.
• Running: The process is an execution state.
• Terminated: Terminated state specifies the time
when a process is terminated
• After completing every step, all the resources are used by
a process, and memory becomes free.
Process Control Block(PCB)

• Every process is represented in the operating


system by a process control block, which is also
called a task control block/ process descriptor.
• A process control block (PCB) is a data structure
used by computer operating systems to store all the
information about a process.
• When a process is created the operating system
creates a corresponding process control block.
Process Control Block (PCB)
• Process ID:
This shows the id/number of the particular process.
• Process State:
This specifies the process state i.e. new, ready,
running, waiting or terminated.
• Program Counter:
This contains the address of the next instruction that
needs to be executed in the process.
• Registers:
This specifies the registers that are used by the
process. They may include accumulators, index
registers, stack pointers, general purpose registers
etc.
• CPU Scheduling Information:
The process priority, pointers to scheduling queues
etc.
• Memory Management Information:
• includes the page tables or the segment tables
depending on the memory system used.
• Accounting information:
• The time limits, amount of CPU used, process
numbers etc.
• I/O Status Information:
• This information includes the list of I/O devices
used by the process, the list of files etc.
Process Scheduling
• Multiprogramming: maximum CPU utilization
• Time sharing: minimize response time.
• The process scheduler selects an available
process for program execution on the CPU.
• The act of determining which process is in
the ready state, and which process should be
moved to the running state is known
as Process Scheduling.
Scheduling Queue
• All processes, upon entering into the system,
are stored in the Job Queue.
• Processes in the Ready state are placed in
the Ready Queue.
• Processes waiting for a device to become
available are placed in Device Queues. There
are unique device queues available for each
I/O device.
Queuing diagram representation of process scheduling
• Queues are stored as a linked list.

• Ready queue header contains pointer to the


first and final PCB in the list.

• Each PCB includes a pointer field that points to


next PCB in ready queue.
Process Life Cycle

Suspend ready

Suspend wait
Schedulers

• Schedulers are special system software which handle


process scheduling in various ways.
• Their main task of scheduler is
• select the process
• submitted into the system
• decide which process to run.
• Schedulers are of three types −
• Long-Term Scheduler
• Short-Term Scheduler
• Medium-Term Scheduler
Long Term Scheduler

• It is also called a job scheduler.


• A long-term scheduler determines which programs are
admitted to the system for processing.
• It selects processes from the queue and loads them
into memory for execution. Process loads into the
memory for CPU scheduling.
• It also controls the degree of multiprogramming.
• If the degree of multiprogramming is stable, then the
average rate of process creation must be equal to the
average departure rate of processes leaving the
system.
Short Term Scheduler

• It is also called as CPU scheduler.


• Its main objective is to increase system performance It is
the change of ready state to running state of the process.
• CPU scheduler selects a process among the processes
that are ready to execute and allocates CPU to one of
them.
• Short-term schedulers, also known as dispatchers, make
the decision of which process to execute next.
• Short-term schedulers are faster than long-term
schedulers.
Medium Term Scheduler

• It is process swapping scheduler.


• It removes the processes from the memory.
• A running process may become suspended if it makes
an I/O request. A suspended processes cannot make
any progress towards completion.
• In this condition, to remove the process from memory
and make space for other processes, the suspended
process is moved to the secondary storage.
• This is called swapping, and the process is said to be
swapped out or rolled out.
Context Switch

• A context switch is the mechanism to store


and restore the state or context of a CPU in
Process Control block so that a process
execution can be resumed from the same
point at a later time.
• Context switching is an essential part of a
multitasking operating system features.
When the process is
switched,,,,,,,,,,
Program Counter
Scheduling information
register value
Changed State
I/O State information
Accounting information
Operation on process
Process Creation
• 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.
• 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.
For example, suppose the parent is to execute c=a+b;
while the child has to execute a=e+f;
Now, the parent can not proceed until the value of ‘a’
is calculated by the child.
resources allocation:
Children may have all resources of parent process.
Subset or part of resources of parent process.
• There are also two possibilities in terms of the
address space of the new process:
1. The child process is a duplicate of the parent
process (it has the same program and data as the
parent).
Program to be executed and data is required.
2. The child process has a new program loaded into it.
When the fork() call is used and child is created successfully,
the id of child process will be returned to parent process
and 0 will be returned to the child process.
main()
{
Fork();
printf(“hello”);
}

Output:
hello
hello
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, and I/O buffers—are
deallocated by the operating system.
• 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 of the process that is to be
terminated.
• Otherwise users could arbitrarily kill each
others job.
• A parent may terminate the execution of one of its
children for a variety of reasons:
• The child has exceeded its usage of some of the
resources that it has been allocated.
• The task assigned to the child is no longer required.
(If parent doesn’t required that task)
• The parent is exiting, and the operating system
does not allow a child to continue if its parent
terminates.
Cooperating Process

• Cooperating processes are those that can


affect or are affected by other processes
running on the system.
• Cooperating processes may share data with
each other.
Reasons for cooperating processes

• Modularity:
dividing complicated tasks into smaller subtasks.
leads to faster and more efficient completion.
• Information Sharing:
access to the same files.
processes can access the files in parallel to each
other.
• Computation Speedup:
Subtasks of a single task can be performed in
parallel .
increases the computation speedup .
• Convenience:
individual user may work on many tasks at
the same time.
For instance, a user may be editing, printing,
and compiling in parallel.
Methods of Cooperation

• Cooperating processes require an interprocess


communication (IPC) mechanism that will
allow them to exchange data and information.
(1) shared memory.
(2) message passing.

You might also like