Process Concept
Process Concept
2.1 PROCESSES
2.1 Process Concept
• A process is an instance of a program in execution.
• Batch systems work in terms of "jobs". Many modern process concepts are still
expressed in terms of jobs, (e.g. job scheduling), and the two terms are often used
interchangeably.
2.1.1 The Process
Process memory is divided into four sections as shown in Figure below:
The text section comprises the compiled program code, read in from non-volatile
storage when the program is launched.
The data section stores global and static variables, allocated and initialized prior to
executing main.
The heap is used for dynamic memory allocation, and is managed via calls to new,
delete, malloc, free, etc.
The stack is used for local variables. Space on the stack is reserved for local variables
when they are declared (at function entrance or elsewhere, depending on the
language ), and the space is freed up when the variables go out of scope. Note that the
CS8493-OPERATING SYSTEMS
ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY
stack is also used for function return values, and the exact mechanisms of stack
management may be language specific.
Note that the stack and the heap start at opposite ends of the process's free space and
grow towards each other. If they should ever meet, then either a stack overflow error
will occur, or else a call to new or malloc will fail due to insufficient memory available.
When processes are swapped out of memory and later restored, additional
information must also be stored and restored. Key among them are the program
counter and the value of all program registers.
2.1.2 Process State
Processes may be in one of 5 states, as shown in Figure below.
CS8493-OPERATING SYSTEMS
ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY
2.1.4 Threads
Modern systems allow a single process to have multiple threads of execution, which
execute concurrently.
2.2 Process Scheduling
The two main objectives of the process scheduling system are to keep the CPU busy at
all times and to deliver "acceptable" response times for all programs, particularly for
interactive ones.
The process scheduler must meet these objectives by implementing suitable policies
for swapping processes in and out of the CPU.
CS8493-OPERATING SYSTEMS
ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY
Job queue − This queue keeps all the processes in the system
.
Ready queue − This queue keeps a set of all processes residing in main
memory, ready and waiting to execute. A new process is always put in this
queue.
Device queues − The processes which are blocked due to unavailability of an
I/O device constitute this queue.
CS8493-OPERATING SYSTEMS
ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY
2.2.2 Schedulers
• A long-term scheduler is typical of a batch system or a very heavily loaded
system. It runs infrequently, It is also called a job scheduler. It selects processes from the
queue and loads them into memory for execution.
• The short-term scheduler, or CPU Scheduler, runs very frequently, on the order
of 100 milliseconds, and must very quickly swap one process out of the CPU and swap in
another one. CPU scheduler selects a process among the processes that are ready to execute
and allocates CPU to one of them.
• Some systems also employ a medium-term scheduler. When system loads get
high, this scheduler will swap one or more processes out of the ready queue system for a few
seconds, in order to allow smaller faster jobs to finish up quickly and clear the system. See the
differences in Figures below.
• An efficient scheduling system will select a good process mix of CPU-bound
processes and I/O boundprocesses.
CS8493-OPERATING SYSTEMS
ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY
CS8493-OPERATING SYSTEMS
ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY
CS8493-OPERATING SYSTEMS