Professional Documents
Culture Documents
7-PPT Used in class-22-Jul-2019Material - II - 22-Jul-2019 - Operating - System - Structure - LEC2
7-PPT Used in class-22-Jul-2019Material - II - 22-Jul-2019 - Operating - System - Structure - LEC2
OS Structure
Application Software
Yahoo
Firefox Second Life GMail
Chat
Hardware Network
2
A Peek into Unix
Application
Kernel space/level
Portable OS Layer • User/kernel modes are
supported by hardware
Machine-dependent layer
•Some systems do not have
clear user-kernel boundary
Application
• Written by programmer
Applications • Compiled by programmer
• Use function calls
Libraries
Portable OS Layer
Machine-dependent layer
Unix: Libraries
• Provided pre-compiled
Application • Defined in headers
• Input to linker (compiler)
• Invoked like functions
Libraries (e.g., stdio.h) • May be “resolved” when
program is loaded
Portable OS Layer
Machine-dependent layer
Typical Unix OS Structure
Application
Libraries
Portable OS Layer
• System calls (read, open..)
• All “high-level” code
Machine-dependent layer
Typical Unix OS Structure
Application
Libraries • Bootstrap
• System initialization
• Interrupt and exception
• I/O device driver
Portable OS Layer • Memory management
• Kernel/user mode
switching
Machine-dependent layer • Processor management
I/O Device Access
• System Calls
– Application makes a system call
– Kernel translates to specific driver
– Driver starts I/O
– Polls device for completion
• Interrupts
– Application starts device
– Asks for an interrupt upon completion
– OS blocks application
– Device controller generates interrupt
System Calls versus Function Calls
Function Call
Process
fnCall()
Process Process
fnCall() sysCall()
OS
9: Return to user
6: Switch to kernel mode
mode (return
address saved on 10: Return to user
stack) program (via trap)
4 – 5: Library call
(puts syscall # in 11: Clean up
CPU register)
1 – 3: Push
parameter (in
7: Find system call
reverse order)
handler
8: Run handler
(index via table of
pointers to
syscall handles)
API – System Call – OS Relationship
Standard C Library Example
• C program invoking printf() library call,
which calls write() system call
Examples of System Calls
• Examples
– getuid() //get the user ID
– fork() //create a child process
– exec() //executing a program
• Don’t mix system calls with standard library calls
– Differences?
– Is printf() a system call?
man syscalls
– Is rand() a system call?
Processes
• What is a process?
• Birth
– How do I make one?
• Life
– Wait for one?
• Death
– Kill one?
Process State
• As a process executes, it changes state
– new: The process is being created
– running: Instructions are being executed
– waiting: The process is waiting for some event
to occur
– ready: The process is waiting to be assigned to
a processor
– terminated: The process has finished execution
Diagram of Process State
Process Control Block (PCB)
Information associated with each process
(also called task control block)
• Process state – running, waiting, etc
• Program counter – location of
instruction to next execute
• CPU registers – contents of all process-
centric registers
• CPU scheduling information- priorities,
scheduling queue pointers
• Memory-management information –
memory allocated to the process
• Accounting information – CPU used,
clock time elapsed since start, time
limits
• I/O status information – I/O devices
allocated to process, list of open files
CPU Switch From Process to Process
Communications Models
2 State Model
Processes
dispatch
enter exit
not
running
running
System pause
queue
enter dispatch exit
processor
pause
2 State Model
Processes
dispatch
enter exit
not
running
running
System pause
queue
enter dispatch exit
processor
What information
do we need to keep pause
in the queue?
Five State Process Model
• Running
– Currently executing
– On a single processor machine, at most one process in the “running” state
• Ready
– Prepared to execute
• Blocked
– Waiting on some event
• New
– Created, but not loaded into memory
• Done
– Released from pool of executing processes
5 State Model - Transitions
• Null (nothing) to New
– New process creation
running done
enter
running done
enter run
I/O
process created
request
quantum
expired
new ready blocked
I/O complete