0% found this document useful (0 votes)
20 views

Operating System: Cset209

The document discusses the key functionality of operating systems including process management, memory management, I/O management, file management, and security. It focuses on process management, describing processes and process states, process control blocks (PCBs), context switching, scheduling, and system calls. Processes are programs in execution that operate using resources allocated by the OS. The OS manages processes through their lifecycle using process states, PCBs containing process attributes, and scheduling processes via short-term schedulers and dispatchers.

Uploaded by

xpershan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Operating System: Cset209

The document discusses the key functionality of operating systems including process management, memory management, I/O management, file management, and security. It focuses on process management, describing processes and process states, process control blocks (PCBs), context switching, scheduling, and system calls. Processes are programs in execution that operate using resources allocated by the OS. The OS manages processes through their lifecycle using process states, PCBs containing process attributes, and scheduling processes via short-term schedulers and dispatchers.

Uploaded by

xpershan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

OPERATING

SYSTEM: CSET209
FUNCTIONALITY OF OS

OS
Functionality

Process Memory I/O File


Security
Management Management Management Management
PROCESS MANAGEMENT

Contents to be Discussed
1. Process management
 Process and its state diagram
 Process Control Block
2. Context switching
3. Schedular and dispatcher
4. System calls and interrupts

4
PROCESS S

• A process is a program in execution.


• A process can also be defined as:
 An instance of a running program
 The entity that can be assigned to, and executed on, a processor
 A unit of activity characterized by a single sequential thread of execution, a current state
and an associated set of system resources
• A process is an active entity, whereas a program is considered to be a passive entity
• Process needs resources :
 CPU time
 Memory
 files
 I/O device
to accomplish its tasks
PROCESS S

• Resources are allocated to a process when it is created or during execution.


• A process is the unit of work within a system.
• A system consists of a collection of processes.
• OS processes execute system code, user code
• Processes can be executed concurrently (parallel) or sequential
• Program can be single thread or Multithreading
Thread
• Thread is a sequence of instructions that can be managed independently
• Thread is the component of process
• Multithreading more than one thread in the same process share resources and memory
PROCESS S

The operating system is responsible for the following activities in connection with
Process Management:

 Scheduling processes and threads on the CPUs.


 Creating and deleting both user and system processes.
 Suspending and resuming processes.
 Providing mechanisms for process synchronization.
 Providing mechanisms for process communication.
CONCEPT OF PROCESS

DOUBLE CLICKING/
COMMAND LINE
EXECUTION OF
Program PROG.EXE OR A.OUT
(executable file) Process
Passive entity (active entity)

HDD

RAM

Process: Program under execution called process

7
ATTRIBUTES AND PCB OF A PROCESS

The Process Control Block (PCB) is typically stored in the


kernel space of the operating system.
ATTRIBUTES AND PCB OF A PROCESS
class PCB:
# Example usage:
def __init__(self, pid, program_counter, registers,
process_state, memory_info, open_files, priority, pid = 1
cpu_scheduling_info, accounting_info, io_status_info): program_counter = 0x1000
self.pid = pid registers = {'eax': 0, 'ebx': 0, 'ecx': 0, 'edx': 0}
self.program_counter = program_counter process_state = 'READY'
self.registers = registers memory_info = {'base_address': 0x1000, 'limit': 0x2000}
self.process_state = process_state open_files = ['file1.txt', 'file2.txt']
self.memory_info = memory_info priority = 1
self.open_files = open_files cpu_scheduling_info = {'time_executed': 0, 'time_remaining':
self.priority = priority 100}

self.cpu_scheduling_info = cpu_scheduling_info accounting_info = {'cpu_time_used': 0, 'start_time': 0}

self.accounting_info = accounting_info io_status_info = {'waiting_on_device': None}

self.io_status_info = io_status_info
ATTRIBUTES AND PCB OF A PROCESS
The Attributes of the process are used by the Operating System to create the process control
block (PCB) for each of them. This is also called context of the process. Attributes which are
stored in the PCB are described below:

1. Process ID: When a process is created, a unique id is assigned to the process which is used
for unique identification of the process in the system.

2. Program counter: A program counter stores the address of the last instruction of the
process on which the process was suspended. The CPU uses this address when the execution
of this process is resumed.

3. Process State: The Process, from its creation to the completion, goes through various
states which are new, ready, running and waiting.

4. Priority: Every process has its own priority. The process with the highest priority among
the processes gets the CPU first. This is also stored on the process control block.
ATTRIBUTES AND PCB OF A PROCESS
5. General Purpose Registers: Every process has its own set of registers which are used to
hold the data which is generated during the execution of the process.
 instruction register (IR)
 memory buffer register (MBR)
 memory data register (MDR)
 memory address register (MAR)

6. List of open files: During the Execution, Every process uses some files which need to be
present in the main memory. OS also maintains a list of open files in the PCB.

7. List of open devices: OS also maintain the list of all open devices which are used during
the execution of the process.
ATTRIBUTES AND PCB OF A PROCESS

Process Control Block or Task Control Block or Process


Descriptor: PCB serves as repository that contains attributes
of process. Attributes may include process state, process
number, program counter, list of open files, registers, process
priority etc. Each process in the system is represented by a
PCB

Figure- Process control block (PCB)


CPU SWITCH FROM PROCESS TO PROCESS
• When CPU switches to another
process, the system must save the
state of the old process and load the
saved state for the new process.

• Context-switch time is overhead; the


system does no useful
work while switching.

• Time dependent on hardware support.

Fig: Diagram showing CPU switch from process to process


1. PROCESS STATE LIFE CYCLE MODEL
• As a process executes, it changes state

• new: The process is being created.

• ready: The process is waiting to be assigned to a processor.

• running: Instructions are being executed.

• waiting: The process is waiting for some event (I/O


operations) to occur.

• terminated: The process has finished execution.


PROCESS STATE LIFE CYCLE MODEL

new 1 3.2 Timeout/ 3.1 terminated


interrupt

ready 2 running
Scheduler
dispatch

waiting

3.3
3. PROCESS SCHEDULING
VM2
To meet the objectives of Multiprogramming, Schedulers are responsible for selecting a
process for scheduling. Three types of scheduler are:

VM3
Slide 21

VM2 Maximum CPU utilization.


Vivek Mehta, 1/23/2023

VM3 Swapping may be necessary to improve the process mix or because


a change in memory requirements has overcommitted available memory,
requiring memory to be freed up.
Vivek Mehta, 1/23/2023
QUIZ
TIME

If the short-term scheduler takes 20 milliseconds to decide to execute a process or 100 milliseconds, then

what percentage of the CPU is being used (or wasted) simply for scheduling the work, considering the

short time between executions?


DISPATCHER

• It is the module that gives control of the CPU to the process selected by the short-time
scheduler.

• A dispatcher switches execution from one process to another process called context switching.
It also setup user registers, memory mapping, etc.

• Dispatch latency: amount of time taken by the system to stop one process and give permission
to another process to being execution.

18
SYSTEM CALLS IN OS

 A system call is a method for a computer program to request a service from the kernel
of the operating system on which it is running. It is the only method to access the
kernel system. All programs or processes that require resources for execution must use
system calls.
 Even simple programs may make heavy use of the operating system. Frequently,
systems execute thousands of system calls per second.
 Mostly accessed by programs via a high-level Application Programming Interface
(API) rather than direct system call use.
AN EXAMPLE OF SYSTEM CALL USAGE
 System call sequence to copy the contents of one file to another file
TYPES OF SYSTEM CALLS
Types of System Calls Windows Linux
CreateProcess()
fork()
ExitProcess()
Process Control exit()
WaitForSingleObject()
wait()
CreateFile() open()
ReadFile() read()
File Management WriteFile() write()
CloseHandle() close()

SetConsoleMode() ioctl()
ReadConsole() read()
Device Management
WriteConsole() write()

GetCurrentProcessID() getpid()
SetTimer() alarm()
Information Maintenance
Sleep() sleep()

CreatePipe()
pipe()
CreateFileMapping()
Communication shmget()
MapViewOfFile()
mmap()
WHAT IS INTERRUPT IN OS?

 An interrupt is a signal emitted by hardware or software when a process or an event


needs immediate attention. It alerts the processor to a high-priority process requiring
interruption of the current working process. In I/O devices, one of the bus control
lines is dedicated for this purpose and is called the Interrupt Service Routine (ISR0).
 When a device raises an interrupt at the process, the processor first completes the
execution of an instruction. Then it loads the Program Counter (PC) with the address
of the first instruction of the ISR. Before loading the program counter with the
address, the address of the interrupted instruction is moved to a temporary location.
Therefore, after handling the interrupt, the processor can continue with the process.
TYPES OF INTERRUPT

1. Hardware Interrupts
 A hardware interrupt is a condition related to the state of the hardware that may be
signaled by an external hardware device, e.g., an interrupt request (IRQ) line on a PC,
or detected by devices embedded in processor logic to communicate that the device
needs attention from the operating system. For example, pressing a keyboard key or
moving a mouse triggers hardware interrupts that cause the processor to read the
keystroke or mouse position.
 External Interrupts: These are generated by external hardware devices, such as
keyboards, mice, or other peripherals, to signal that they require attention.
 Timer Interrupts: These are generated by the system's timer or clock to perform
tasks at regular intervals, such as updating the system clock or preempting the current
process.
TYPES OF INTERRUPT

2. Software Interrupts
 The processor requests a software interrupt upon executing particular instructions or
when certain conditions are met. Software interrupts may also be unexpectedly
triggered by program execution errors. These interrupts are typically
called traps or exceptions.
 System Calls: Software interrupts can be triggered by software instructions or
system calls, allowing a program to request services from the operating system,
such as reading from or writing to files.
TYPES OF INTERRUPT

 Exception Interrupts:
 Faults: These occur due to errors in the program, such as division by zero or accessing
invalid memory.
 Traps: These are intentional interrupts generated by the program for debugging or other
purposes.
 Abort: These occur when a severe error is detected, and the program or system must be
terminated.
TYPES OF INTERRUPT

 Maskable and Non-Maskable Interrupts:

 Maskable Interrupts: These can be temporarily ignored or delayed by the processor under
certain conditions. The processor can be configured to mask or enable specific interrupts.

 Non-Maskable Interrupts (NMI): These interrupts cannot be ignored or delayed by the


processor and are typically reserved for critical events that require immediate attention.
HOW INTERRUPT HANDLING IS DONE ?
 Whenever an interruption occurs the processor
finishes the current instruction execution and
starts the execution of the interrupt known as
interrupt handling.
 The interrupt handling mechanism of an operating
system accepts a number which is an address and
then selects what specific action to be taken which
is already mentioned in the interrupt service
routine. In most architecture, the address is stored
in a table known as a vector table. Interrupt
handling by OS scheme is shown as follows:
THANK YOU
?

You might also like