Module 1
Module 1
• Computer-system operation
– One or more CPUs, device controllers connect
through common bus providing access to
shared memory
– Concurrent execution of CPUs and devices
competing for memory cycles
Why do we need an Operating System?
Hardware (resource)
Disk
Input/
CPU Memory Output
PC Motherboard
Computer-System Operation
Shell
Operating
System
CPU Memory
Video Card Network
Monitor Disk Printer
Why is abstraction important?
• Without OSs and abstract interfaces, application writers must
program all device access directly
– load device command codes into device registers
– understand physical characteristics of the devices
• Applications suffer!
– very complicated maintenance and upgrading
– no portability
What Operating Systems Do
(User’s view)
Depends on the point of view
• Single user system
• Users want convenience, ease of use
– Don’t care about resource utilization
• OS is a control program
– Controls execution of programs to prevent
errors and improper use of the computer
Concept of Process
• Process
– Program loaded in memory and in execution
• Program is a passive entity
• Process is an active entity
12
Types of Systems
• Batch Systems
– Multiple jobs, but only one job in memory at one
time and executed (till completion) before the next
one starts
Operating system
User program
Jobs waiting
Types of Systems
• Multiprogrammed Systems
– Multiple jobs in memory, CPU is
multiplexed between them
– Single user cannot keep CPU and
I/O devices busy at all times
– When it has to wait (for I/O for
example), OS switches to another
job
– Multiprogramming organizes jobs
(code and data) so CPU always has
one to execute
– A subset of total jobs in system is
kept in memory
– One job selected and run via job
• Effective resource utilization
scheduling
• Poor user experience
Types of Systems
• Time-sharing Systems (multitasking)
logical extension of multiprogramming in which CPU switches jobs so
frequently that users can interact with each job while it is running, creating
interactive computing
– Response time should be < 1 second
– Each user has at least one program executing in memory
– If several jobs ready to run at the same time CPU scheduling
• OS is a control program
– Controls execution of programs to prevent
errors and improper use of the computer
Manage resources
Job 1
Memory
Role of Operating system
Operating
System
Process
Device Mgmt
Mgmt File System Network
Protection Comm. Kernel
Security
CPU Memory
Video Card Network
Monitor Disk Printer
24
Execution of OS
• Interrupt driven
• Until an interrupt comes, OS remains Idle
• User program invokes OS code by generating
Interrupt, system call
– To perform some task reserved for OS
– Accessing I/O devices (read, write files)
• Any difference in execution between user and
OS program?
Dual-mode Operation
Operating
System
Process
Device Mgmt
Mgmt File System Network
Protection Comm. Security
CPU Memory
Video Card Network
Monitor Disk Printer
29
Control program (Protection)
• Multiple jobs are sharing the common resource
– With sharing, many processes could be adversely affected by a bug in
one program
– Make sure that error in one program could cause problems only for that
program
– A job gets stuck in an infinite loop J2, J3
• Prevent correct operations of other jobs waiting
CPU
(J1)
– One erroneous program might modify another program, even operating
system
Incorrect program cannot
cause other programs to
execute incorrectly
Dual-mode operation allows OS to protect
itself and other system components
Privilege instructions
A2
computation
Initiates
I/O
Time
Schedules A1
Schedules A2
System calls Win 32
POSIX
Application JVM
System Calls: fork(), wait(), read(), open(), write(), mkdir(), kill() ...
Operating
System
Process
Device Mgmt
Mgmt File System Network
Protection Comm. Security
CPU Memory
Video Card Network
Monitor Disk Printer
33
Standard C Library Example
• C program invoking printf() library call,
which calls write() system call
Resources Managed by OS
• Physical
– CPU, Memory, Disk, I/O Devices like keyboard,
monitor, printer
• Logical
– Process, File, …
Hence we have
1. Process management
2. Memory management
3. File management
4. I/O management
Process Management
• A process is a program in execution. Program is a passive
entity, process is an active entity.
• Process needs resources to accomplish its task
– CPU time
• Representation of process
– Process has one program counter specifying location of next
instruction to execute
– Data structure (stores information of a process)
• Many processes may be associated with the same program
• Typically system has many processes
– some user processes,
– some operating system processes
• Life cycle of a process
– States
– Arrival, Computation, I/O, I/O completion, termination
Process Management Activities
The operating system is responsible for the following
activities in connection with process management:
• Process terminates => MMU declares that the memory space is available
• Multiprogramming: Memory management manages several processes in memory
– Optimizing CPU utilization and computer response to users
• Ensure memory protection
– Track illegal address
• Memory management activities
– Keeping track of which parts of memory are currently being used and by which process
– Allocating and deallocating memory space as needed
• Introduces Virtual memory
– If the process size is bigger than the RAM size
• Hardware support
File Management
User
Files (user’s
view)
Device Driver Mapping
Disk
Physical media (sector,
track)
File Management
I/O devices
OS design and structure
• Large complex system
– Designed carefully
• if it is to function properly
• Modified easily
• Common approach
– Partition the tasks into small
components/modules
– Each module must accomplish some specified task
Design and Implementation