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

Operating System Theory1

The document outlines an Operating System lab course led by Dr. Abhijit Dasgupta, covering fundamental UNIX commands, system calls, shell scripting, and process management. It explains the role of an operating system in managing hardware resources, processes, and memory, as well as the concepts of process states and scheduling. References for further reading are also provided, including notable textbooks on operating systems.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Operating System Theory1

The document outlines an Operating System lab course led by Dr. Abhijit Dasgupta, covering fundamental UNIX commands, system calls, shell scripting, and process management. It explains the role of an operating system in managing hardware resources, processes, and memory, as well as the concepts of process states and scheduling. References for further reading are also provided, including notable textbooks on operating systems.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Operating System Lab

Dr. Abhijit Dasgupta


Assistant Professor
Department of Computer Science and Engineering
SRM University, AP
Course Overview

• Basic UNIX Commands;


• UNIX system calls for process management and inter-process
communication;
• Shell Script;
• Experiments on process scheduling and other operating system tasks
through simulation/implementation.
References

• Abraham Silberschatz Peter B. Galvin and Greg Gagne, Operating


System Concepts, Wiley 8th Edition, 2008.
• Garry. J. Nutt, Operating Systems: A Modern Perspective, Addison-
Wesley
• Andrew S. Tanenbaum and Herbert Bros, Modern Operating Systems
(4th Edition), Pearson
• Sumitabha Das, UNIX Concepts and Applications, Tata McGraw-Hill
What is an
operating system?
• Middleware between user
programs and system
hardware.
• Manages hardware: CPU,
main memory, IO devices
(disk, network card,
mouse, keyboard etc.)
What happens when you run a program?
(Background)

• A compiler translates high level programs into an executable (“.c” to


“a.out”)
• The exe contains instructions that the CPU can understand, and data
of the program (all numbered with addresses)
• Instructions run on CPU: hardware implements an instruction set
architecture (ISA)
• CPU also consists of a few registers, e.g., – Pointer to current
instruction (program counter or PC) – Operands of instructions, memory
addresses
So, what happens when you run a program?

• To run an exe, CPU


– fetches instruction pointed at by PC from memory
– loads data required by the instructions into registers
– decodes and executes the instruction
– stores results to memory

• Most recently used instructions and data are in CPU caches for faster
access
So, what does
the OS do?
• OS manages program
memory – Loads program
executable (code, data)
from disk to memory
• OS manages CPU –
Initializes program counter
(PC) and other registers to
begin execution
• OS manages external
devices – Read/write files
from disk.
OS manages
CPU
• OS provides the process
abstraction – Process: a
running program – OS
creates and manages
processes
• Each process has the
illusion of having the complete
CPU, i.e., OS virtualizes CPU
• Timeshares CPU between
processes
• Enables coordination
between processes
OS manages
memory
• OS manages the memory
of the process: code, data,
stack, heap etc.
• Each process thinks it has a
dedicated memory space for
itself, numbers code and data
starting from 0 (virtual
addresses)
• OS abstracts out the details
of the actual placement in
memory, translates from
virtual addresses to actual
physical addresses
OS manages devices
• OS has code to manage disk, network
card, and other external devices: device
drivers.
• Device driver talks the language of the
hardware devices – Issues instructions to
devices (fetch data from a file) –
Responds to interrupt events from devices
(user has pressed a key on keyboard).
• Persistent data organized as a file
system on disk.
Design goals of an operating system

• Convenience, abstraction of hardware resources for user programs


• Efficiency of usage of CPU, memory, etc.
• Isolation between multiple processes
Processes and process management

• The process concept


• The threads concept
• Inter-process communication
• Process scheduling
• Scheduling Algorithms
• Deadlocks
Process concept
• Process is program in execution
• Process need resources like
• CPU times
• Memory
• Files
• I/O devices
• Resources are allocated to processes either
• When it created
• While it executed
• Process can be –
• operating system process –execute system code
• User process – execute user code
• The OS responsible (process management)
• Creation and deletion of process
• Scheduling of process
• Provision of mechanism for synchronization communication
• Dead lock handling for the process
The process
• A process is more than program – because it
• Include the current activity – represent by the value of program counter
• A content of processor register
• A process also has process
• Stack (contain temporary data like subroutine variables) , return address and
temporary variables )
• Data section containing global variables
• Two process may be associated with the same program – are considered two
separate execution sequences
• Example: a user may invoke many copies of the editor program
• Each are separate process , but their text section are equivalent ,data
section will vary
Process in
memory
Process state

• As process execute , it will change state


• Each process may be in one of the following state
• New – a process is being created
• Running – instruction are executed
• Waiting – waiting for some event to occur (like I/O completion )
• Ready – a process is waiting to be assigned to processor
• Terminated – a process has finished execution
New admitted
Scheduler dispatch
terminated

exit
Ready

Running
I/O event Interrupt
compilation

Waiting I/o or event wait

N.B : Only one process running at a time


Many process are in ready or waiting state

Process state
Process control Block
Each process is represented in OS by process control block (PCB)

Pointer Process
state
Process number

Program counter

Register
Memory limit

List of open files

.
.

Process control block


• A PCB contain specific information for each process like
• Process state
• Program counter – the counter indicates the address of the
next instruction to be executed for this process
• CPU registers – (vary in number and in type depends on
the computer architecture ) like AC , general purpose
register - this state must be saved when an interrupt
occurs
• CPU scheduling info : info like process priority , pointer to
scheduling queues
• Memory management info : info like the values of base and
limit register , page tables
• I/O status info : list of I/O devices allocated to this process
Process p0
Process p1
Interrupt or system call

Save state info PCB0


Idle

Reload state from PCB1


Idle Executing
Interrupt or system call
Save state info PCB1

Idle

Reload state from PCB0

CPU switch from process to process


Process scheduling

• Objective of multi programming – is to have process always


running – maximize CPU utilization

• Objective of time sharing – to switch CPU among process – user


can interact with each program
• Processes that are in main memory
are ready to execute are kept on a
list called ready queue (in linked list )
• A ready queue header will contain
pointer to the first and last PCBs in
the list.
Scheduling • Each PCB has a pointer field that
queues point to the next process in the ready
queue
• A list of process waiting for the I/O
devices is called a device queue
• Each device has its own device
queue.
Ready Queue And
Various I/O Device
Queues
Scheduler

• An OS select process from the queues in some fashion

• The selection process is carried out by the appropriate scheduler.


Ready queue CPU

I/O I/O request

Time slice expired

Fork a child
Child execute

Interrupt Wait for an interrupts


occurs

Queuing diagram representation of process scheduling


• Long term scheduling – select job from the pool (disk) and
load in the memory for the execution
• Execute less frequently
• Control the degree of multi programming
• Short term scheduler (CPU scheduler ) – select from the
ready process to execute
• Execute so frequently
• Most process can be either I/O bound, or CPU bound
• I/O bound process is a process that spends more of the
time doing I/O than it spends doing execution
• A CPU bound process – is one generates I/O requests
infrequently (most of its time is computation )
• A long-term scheduler select a good process
mix of I/O bound and CPU bound process
• OS like time sharing system – introduce
intermediate level of scheduling

Partially executed Swap out


Swapped out process

End
CPU
Ready queue

I/O waiting
I/O queue

Medium term scheduler – scheduling to the queues


Next Class
• More Concepts on Process
• Inter-process communication

You might also like