3.operating System - Process
3.operating System - Process
System: Process
Dr. Jit Muherjee
Concept of Process
● An operating system executes a variety of programs
○ batch systems - jobs
○ time-shared systems - user programs or tasks
○ Job, task and program used interchangeably
● A process is basically a program in execution.
○ The execution of a process must progress in a sequential fashion.
● A computer program is a collection of instructions that performs a specific task when
executed by a computer.
○ a process is a dynamic instance of a computer program
● A process is defined as an entity which represents the basic unit of work to be implemented in
the system.
● When a program is loaded into the memory and it becomes a process,
● The process is not as same as program code but a lot more than it. A process is an 'active'
entity as opposed to the program which is considered to be a 'passive' entity.
Process and Program
More to a process than just a
program:
● Program is just part of the
process state
● I can run Vim or Notepad
on lectures.txt, you can
run it on homework.java –
Same program, different
processes
Less to a process than
a program:
1. Process State - The current state of the process i.e., whether it is ready, running, waiting, or whatever.
2. Process privileges - This is required to allow/disallow access to system resources.
3. Process ID - Unique identification for each of the process in the operating system.
4. Pointer - A pointer to parent process.
5. Program Counter - Program Counter is a pointer to the address of the next instruction to be executed for this
process.
6. CPU registers - Various CPU registers where process need to be stored for execution for running state.
7. CPU Scheduling Information - Process priority and other scheduling information which is required to schedule
the process.
8. Memory management information - This includes the information of page table, memory limits, Segment table
depending on memory used by the operating system.
9. Accounting information - This includes the amount of CPU used for process execution, time limits, execution ID
etc.
10. Status information- This includes a list of I/O devices allocated to the process.
Process Scheduling Queues
● Job Queue - set of all processes in the system
● Ready Queue - set of all processes residing in main memory, ready
and waiting to execute.
● Device Queues - set of processes waiting for an I/O device.
● Process migration between the various queues.
● Queue Structures - typically linked list, circular list etc.
Representation
of Process
Scheduling
Process (PCB) moves from
queue to queue
Processes: Concurrency
● Only one process (PCB) active at a time
○ Current state of process held in PCB:
■ “snapshot” of the execution and protection environment
○ Process needs CPU, resources
● Give out CPU time to different processes (Scheduling):
○ Only one process “running” at a time
○ Give more time to important processes
● Give pieces of resources to different processes (Protection):
○ Controlled access to non-CPU resources
○ E.g. Memory Mapping: Give each process their own address space
Processes: Context Switch
● Task that switches CPU from one
process to another process
○ the CPU must save the PCB state of the old
process and load the saved PCB state of the
new process.
● Context-switch time is overhead
○ System does no useful work while switching
○ Overhead sets minimum practical switching
time; can become a bottleneck
● Time for context switch is dependent
on hardware support ( 1- 1000
microseconds).
● Code executed in kernel is overhead
○ Overhead sets minimum practical switching
time
Difference between Multiprogramming and Multitasking
Multiporgramming
Multitasking
● Logical extension of multiprogramming. Multitasking is the ability of an OS to execute more than one task
simultaneously on a CPU machine. These multiple tasks share common resources (like CPU and memory).
In multi-tasking systems, the CPU executes multiple jobs by switching among them typically using a small
time quantum
Difference between Multiprogramming and Multitasking
Multiprogramming Multitasking
1 Both of these concepts are for single CPU. Both of these concepts are for single CPU.
2 Concept of Context Switching is used Concept of Context Switching an time sharing is used
3 Operating system simply switches to, and executes, Switching happens when either allowed time expires or
another job when current job needs to wait. where there other reason for current process needs to
wait
4 Increases CPU utilization by organising jobs . Increases CPU utilization, it also increases
responsiveness.
5 Reduce the CPU idle time for as long as possible. Extend the CPU Utilization concept by increasing
responsiveness Time Sharing.
Preemptive and Cooperative Multitasking
● Preemptive Multitasking - (Windows, Unix)
○ Can initiate a context switching from the running process to another process
○ The operating system allows stopping the execution of the currently running process and allocating the
CPU to some other process.
○ OS decides how long a process should execute before allowing another process to use the operating
system.
○ A malicious program initiates an infinite loop, it only hurts itself without affecting other programs or threads.
○ Preemptive multitasking forces applications to share the CPU whether they want to or not.
● Cooperative Multitasking - (Macos)
○ Operating system never initiates context switching from the running process to another process.
○ A context switch occurs only when the processes voluntarily yield control periodically or when idle or
logically blocked to allow multiple applications to execute simultaneously
○ All the processes cooperate for the scheduling scheme to work.
○ A malicious program can bring the entire system to a halt by busy waiting or running an infinite loop and not
giving up control.
○ In cooperative multitasking, all programs must cooperate for it to work. If one program does not cooperate,
it can hog the CPU.
Schedulers
● Process Scheduling handles the selection of a process for the processor on the basis of a scheduling
algorithm and also the removal of a process from the processor.
● Long Term Scheduler (or job scheduler)
○ Selects processes from the storage pool in the secondary memory and loads them into the ready
queue in the main memory for execution.
○ Controls the degree of multiprogramming.
○ It must select a careful mixture of I/O bound and CPU bound processes to yield optimum system
throughput. If it selects too many CPU bound processes then the I/O devices are idle and if it selects
too many I/O bound processes then the processor has nothing to do.
○ The job of the long-term scheduler is very important and directly affects the system for a long time.
● Short Term Scheduler (or CPU scheduler)
○ The short-term scheduler selects one of the processes from the ready queue using a scheduling
algorithm and schedules them for execution.
○ The short-term scheduler executes much more frequently than the long-term scheduler as a process
may execute only for a few milliseconds.
○ If it selects a process with a long burst time, then all the processes after that will have to wait for a
long time in the ready queue.
○ Dispatcher - Gives control of the CPU to the process selected by the short-term scheduler.
Schedulers