Operating System
Course Instructor:
Poulami Dalapati
Preety Singh
Abhijit Adhikari
Dept. of CSE, LNMIIT Jaipur
Roadmap
A brief introduction
Operating system structures and System call
Processes and threads
Memory management
Storage and file system
Protection and security
OS/CSE222/Poulami D. 2
OS structures
• Basic OS functionality
• Basic architecture
• What the OS can do is dictated in the part by the underlying
architecture
• Architecture can greatly simplify or complicate the OS
Modern OS functionality
• Process and thread management
• Concurrency: Doing many things
• I/O devices: Let the CPU work while a I/O device is working
• Memory management: OS coordinates allocation of memory and
moving data between disk and main memory
• Files: OS coordinates how disk space is used to store multiple files
• Distributed systems and networks: allow a group of workstations to
work together on distributed hardware
Generic computer architecture
Disk Disk Printer Tape drive
Tape
Disk Printer Drive
CPU
controller controller controller
System bus
Memory controller
Memory
Computer architecture
• CPU: processor that performs the actual computation
• I/O devices: terminal, disks, printer etc.
• Memory: RAM containing data and programs used by the CPU
• System bus: communication medium between CPU, memory, and
peripherals
Architectural features and OS services
OS services Hardware support
Protection Kernel/user mode
Protected instruction
Interrupts Interrupt vectors
System calls Trap instructions and trap vectors
I/O Interrupts or memory mapping
Scheduling, error handling Timer
Synchronization Atomic instructions
Virtual memory TLB
Protection
• Kernel mode
• User mode } to protect system from users
Protection
• Kernel mode vs. User mode: some instructions are restricted to use
only by OS. All users may not
• Address I/O directly
• Use instructions that manipulate the state of memory
• Set the mode bits that determine user or kernel mode
• Disable or enable interrupts
• Halt the machine
• In kernel mode, OS can do all these.
• The hardware must support kernel and user mode.
• A status bit in a protected processor register indicates the mode
• Protected instructions can only be executed in kernel mode
Crossing protection boundaries
• System call: OS procedure that executes privileged instructions
System calls (few example!)
Unix Windows
fork createProcess
Exit exitProcess
Read readFile
Write writeFile
System calls
Process Management
Call Description
pid=fork() Create child process identical to parent
pid=waitpid(pid, &statloc, options) Wait for a child to terminate
Exit(status) Terminate process execution and return status
… …
System calls
File Management
Call Description
fd=open(file,<mode> Open a file for reading, writing, or both
s=close(fd) Close an open file
n=read(fd, buffer, nbytes) Read data from a file into a buffer
n=write(fd, buffer, nbytes) Write data from a buffer into a file
… …
Memory protection
• Architecture must provide support so that the OS can
• Protect program from each other
• Protect the OS from user
• Simplest technique is to base and limit registers
• CPU check each user reference (instruction and data
addresses) ensuring it falls between the base and limit
register values; if not OS terminates the process.
What if there is no base and limit registers!
Traps
• Traps: special conditions detected by the architecture
• Eg.: page fault, write to a read-only page, divide by zero etc.
• On detecting a trap the system
• Save the state of process
• Transfers control to appropriate trap handler
• Control jumps to the piece of code which will handle trap
• CPU indexed trap vector (with trap number and look-up table)
• Execution at that address
• On completion OS resumes the process
I/O control
• CPU issues command to I/O devices and continue
• When the I/O device completes the command, it uses an interrupt
• OS processes the I/O devices interrupt
Synchronization
• Interrupts interfere with executing process
• OS most be able to synchronize cooperating, concurrent process
From the Architecture to OS to User
Hardware abstraction OS services User abstraction
Processor Process management Process
Scheduling,
Synchronization
Memory Memory management, Address space
protection,
Virtual memory
I/O devices Concurrency with CPU, Terminal, mouse, printer, System
Interrupt handling calls
File system File management Files
Distributed systems Network security RPC system calls, file sharing
Distributed file systems