Module 2.1 Process
Module 2.1 Process
Scheduling
Swati Mali
Nirmala Shinde Baloorkar
Assistant Professor
Department of Computer Engineering
Outline
• Basic Terminology
• Process
Basic Terminologies &
Definitions
Task
A process can execute in either user mode or kernel mode, with the
processor switching between these modes depending on the code being
executed.
• User Mode: The process runs with limited privileges, typically to
prevent it from performing harmful operations.
• Kernel Mode: The process runs with full access to all system resources
and hardware, necessary for performing critical tasks.
• E.g.: Typing / Editing document
Process Context
• When a running process is taken away from the processor, certain
information about its state needs to be saved to allow it to resume execution
later.
• The process context includes:
• address space,
• stack space,
• virtual address space,
• register set image i.e. Program Counter, Stack Pointer, Program Status Word,
Instruction Register and other general processor registers,
• accounting information,
• associated kernel data structures and
• current state of the process (waiting, ready, etc).
Event
• Process priority:
• In a multiprogramming system, the processes are assigned numerical
privileged values indicating their relative importance and/or urgency and/or
value.
• Preemptive:
• Preemption is the ability of the system to take over a currently executing
process by another one (possibly with high privileged one) with an intention to
resume the preempted process later on.
• Non-preemptive:
• Non-preemptive entities are the one those cannot be taken over by other
entities
Process
Process Component
7/30/2024 15
Process Control
Block (PCB)
• Process Identifier/Number - An
identifier that helps us
in identifying and locating a process.
• Process state –It identifies the state
that the process is currently in. It
could be running, waiting, etc
• Program counter – address of the
next instruction to be executed for this
process.
7/30/2024 16
Process Control
Block (PCB)
CPU registers –
• contents of all process-centric
registers,
• Registers may vary in
number and type depending
on system architecture.
7/30/2024 17
Process Control
Block (PCB)
CPU scheduling information-
• Process priorities,
• scheduling queue pointers,
• any other scheduling
parameters.
7/30/2024 18
Process Control
Block (PCB)
Memory-management
information –
• memory allocated to the
process,
• value of the Base and limit
registers,
• the page tables or segment
tables.
7/30/2024 19
Process Control
Block (PCB)
Accounting information –
• CPU used,
• clock time elapsed since
start, time limits,
• job or process numbers
7/30/2024 20
Process Control
Block (PCB)
I/O status information –
• list of I/O devices
allocated to process,
• list of open files
7/30/2024 21
Process State
As a process executes, it changes state
• New
• When process creation is taking place, the process is in a new state.
• Ready
• During this state, the process is loaded into the main memory and will be placed in
the queue of processes which are waiting for the CPU allocation.
• Running
• Instruction is being executed.
• waiting
• The process is waiting for some event to occur (such as an I/O completion)
• Terminated
• The process has finished execution.
Process state transition
• Interactive logon: when a user logs into the system, a new process is
created.
• Created by OS to provide some service: The OS initiates a process
to perform the service requested by user directly or indirectly, without
making the user to wait.
• Spawned by an existing process: To support Modularity and/or
parallelism, a user program can create some number of new processes.
• Program Execution: Whenever you open an application, the OS
creates a process to run it
How the OS creates a process?
1. Create a process
2. Assign a unique process ID to newly created process
3. Allocate the memory and create its process image
4. Initialize process control block
5. Set the appropriate linkages to the different data structures such as
ready queue etc.
6. Create or expand the other data structures if required
Causes of process blocking
• One process can create another process, perhaps to do some work for
it.
• The original process is called the parent
• The new process is called the child
• The child is an (almost) identical copy of parent (same code, same data, etc.)
• The parent can either wait for the child to complete, or continue executing in
parallel (concurrently) with the child
Process Creation in UNIX (cont…)
• In UNIX, a process creates a child process using the system call fork( )
• Negative: A child process could not be successfully created if
the fork() returns a negative value.
• Zero: A new child process is successfully created if the fork() returns a zero.
• Positive: The positive value is the process ID of a child's process to the parent.
The process ID is the type of pid_t that is defined in OS or sys/types.h.
• Child often uses exec( ) to start another completely different program
Fork()
Example - Process Creation
System Calls for Process Management
Sr System Call Description
No
1 fork() This system calls creates a new process.
2 exec() This call is used to execute a new program on a process.
3 wait() This call makes a process wait until some event occurs.
10 Signal() This system call is invoked for sending and receiving software interrupts
Context Switch
• Context Switch:
• Execution of a process is stopped to respond an interrupt.
• Needs to save Process Image of one process and load process image of the
new process loaded.
• The processes are switched and processes keep on changing their status as
Running and Not running.
• Mode switch:
• Every process may switch in between a low privileged user mode and high
privileged kernel mode in its lifetime.
• Process continues to execute even after mode switches.
CPU Switch From Process to Process
7/30/2024 44
Fundamental kernel functions of process control