CST 206 OPERATING SYSTEMS
MODULE 2
Processes - Process states, Process control block, threads, scheduling, Operations on
processes - process creation and termination – Inter-process communication - shared
memory systems, Message passing systems.
Process Scheduling – Basic concepts- Scheduling criteria -scheduling algorithms- First
come First Served, Shortest Job First , Priority scheduling, Round robin scheduling.
PROCESS CONCEPT
An operating system executes a variety of programs:
• batch system – jobs
• time-shared systems – user programs or tasks.
• Process is a program in execution, its execution must progress in sequential fashion.
• A program is static and passive whereas a process is dynamic and active.
• One program can be several processes (e.g., multiple instances of browser).The process can be started
via GUI or command line entry of its name.
A process has multiple parts:
• the program code, also called text section
• runtime CPU states, including program counter, registers, etc.
• various types of memory:
stack: temporary data e .g., function parameters, local variables, and return addresses
data section: global variables
heap: memory dynamically allocated during runtime
Process in Memory
Figure 1: Process in Memory
PROCESS STATE
As a process executes, it changes state
• new
• ready
• running
1
, CST 206 OPERATING SYSTEMS
• waiting
• terminated
1. Start/ New
This is the initial state when a process is first started/created.
2. Ready
The process is waiting to be assigned to a processor. Ready processes are waiting to have the
processor allocated to them by the operating system so that they can run.
3. Running
Once the process has been assigned to a processor by the OS scheduler, the process state is set to
running and the processor executes its instructions.
4. Waiting
Process moves into the waiting state if it needs to wait for a resource, such as waiting for user input,
or waiting for a file to become available.
5. Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating system, it is moved to the
terminated state.
Diagram of Process State
Figure 2: Process States and Schedulers
PROCESS CONTROL BLOCK (PCB)
In the kernel, each process is represented by a Process Control Block (PCB).It is also called a task control
block .It contains:
• process number (pid)
• process state
• program counter
• CPU registers
• CPU scheduling information
• memory-management data
• accounting data
• I/O status
2
, CST 206 OPERATING SYSTEMS
Process state : The state may be new, ready, running, waiting, terminated, and so on.
Program counter: The counter indicates the address of the next instruction to be executed for this
process.
CPU registers :The registers vary in number and type, depending on the computer architecture. They
include accumulators, index registers, stack pointers, and general-purpose registers, any condition-code
information.
CPU-scheduling information: This information includes a process priority ,
pointers to scheduling queues, and any other scheduling parameters.
Memory-management information : This information may include such items
as the value of the base and limit registers and the page tables, or the segment
tables, depending on the memory system used by the operating system.
Accounting information: This information includes the amount of CPU and real
time used, time limits, job or process numbers, and so on.
I/O status information: This information includes the list of I/O devices
allocated to the process, a list of open files, and so on.
Figure 3: PCB
SCHEDULING QUEUES
• Kernel maintains scheduling queues of processes:
• 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.
• Processes migrate among the various queues.
• For a single-processor system, there will never be more than one running process. If there are
more processes, the rest will have to wait until the CPU is free and can be rescheduled.
• As processes enter the system, they are put into a job queue, which consists of all processes in
the system.
• The processes that are residing in main memory and are ready and waiting to execute are kept
on a list called the ready queue .This queue is generally stored as a linked list. A ready-queue
header contains pointers to the first and final PCBs in the list. Each PCB includes a pointer field
that points to the next PCB in the ready queue . The system also includes other queues. Each
device has its own device queue.
Queues for Process Scheduling
Fig 4: Queues for Process Scheduling
3
MODULE 2
Processes - Process states, Process control block, threads, scheduling, Operations on
processes - process creation and termination – Inter-process communication - shared
memory systems, Message passing systems.
Process Scheduling – Basic concepts- Scheduling criteria -scheduling algorithms- First
come First Served, Shortest Job First , Priority scheduling, Round robin scheduling.
PROCESS CONCEPT
An operating system executes a variety of programs:
• batch system – jobs
• time-shared systems – user programs or tasks.
• Process is a program in execution, its execution must progress in sequential fashion.
• A program is static and passive whereas a process is dynamic and active.
• One program can be several processes (e.g., multiple instances of browser).The process can be started
via GUI or command line entry of its name.
A process has multiple parts:
• the program code, also called text section
• runtime CPU states, including program counter, registers, etc.
• various types of memory:
stack: temporary data e .g., function parameters, local variables, and return addresses
data section: global variables
heap: memory dynamically allocated during runtime
Process in Memory
Figure 1: Process in Memory
PROCESS STATE
As a process executes, it changes state
• new
• ready
• running
1
, CST 206 OPERATING SYSTEMS
• waiting
• terminated
1. Start/ New
This is the initial state when a process is first started/created.
2. Ready
The process is waiting to be assigned to a processor. Ready processes are waiting to have the
processor allocated to them by the operating system so that they can run.
3. Running
Once the process has been assigned to a processor by the OS scheduler, the process state is set to
running and the processor executes its instructions.
4. Waiting
Process moves into the waiting state if it needs to wait for a resource, such as waiting for user input,
or waiting for a file to become available.
5. Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating system, it is moved to the
terminated state.
Diagram of Process State
Figure 2: Process States and Schedulers
PROCESS CONTROL BLOCK (PCB)
In the kernel, each process is represented by a Process Control Block (PCB).It is also called a task control
block .It contains:
• process number (pid)
• process state
• program counter
• CPU registers
• CPU scheduling information
• memory-management data
• accounting data
• I/O status
2
, CST 206 OPERATING SYSTEMS
Process state : The state may be new, ready, running, waiting, terminated, and so on.
Program counter: The counter indicates the address of the next instruction to be executed for this
process.
CPU registers :The registers vary in number and type, depending on the computer architecture. They
include accumulators, index registers, stack pointers, and general-purpose registers, any condition-code
information.
CPU-scheduling information: This information includes a process priority ,
pointers to scheduling queues, and any other scheduling parameters.
Memory-management information : This information may include such items
as the value of the base and limit registers and the page tables, or the segment
tables, depending on the memory system used by the operating system.
Accounting information: This information includes the amount of CPU and real
time used, time limits, job or process numbers, and so on.
I/O status information: This information includes the list of I/O devices
allocated to the process, a list of open files, and so on.
Figure 3: PCB
SCHEDULING QUEUES
• Kernel maintains scheduling queues of processes:
• 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.
• Processes migrate among the various queues.
• For a single-processor system, there will never be more than one running process. If there are
more processes, the rest will have to wait until the CPU is free and can be rescheduled.
• As processes enter the system, they are put into a job queue, which consists of all processes in
the system.
• The processes that are residing in main memory and are ready and waiting to execute are kept
on a list called the ready queue .This queue is generally stored as a linked list. A ready-queue
header contains pointers to the first and final PCBs in the list. Each PCB includes a pointer field
that points to the next PCB in the ready queue . The system also includes other queues. Each
device has its own device queue.
Queues for Process Scheduling
Fig 4: Queues for Process Scheduling
3