Anda di halaman 1dari 31

Operating System Structure

OS Structure

Application Software
Yahoo
Firefox Second Life GMail
Chat

Standard Operating System Interface


Operating System
Standard Device File
Read/Write Communication
Output Control System

Hardware Network

2
A Peek into Unix

Application

Libraries User space/level

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()

Caller and callee are in the same


Process
- Same user
- Same “domain of trust”
System Calls versus Function Calls
Function Call System Call

Process Process

fnCall() sysCall()

OS

Caller and callee are in the same


Process
- Same user - OS is trusted; user is not.
- Same “domain of trust” - OS has super-privileges; user does not
- Must take measures to prevent abuse
Steps for Making a System Call
(Example: read call)
count = read(fd, buffer, nbytes);

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

new ready blocked


5 State Model - Transitions
• New to Ready
– Move to pool of
executable
processes
running done

new ready blocked


5 State Model - Transitions
• Ready to Running
– Chosen to run from
the pool of
processes
running done

new ready blocked


5 State Model - Transitions
• Running to Ready
– Preempted by OS
• Running to Blocked
– Request for an
unavailable resource running done
• Running to Done
– Terminated by the OS

new ready blocked


5 State Model - Transitions
• Blocked to Ready
– Resource is now available

running done

new ready blocked


5 State Model - Transitions
• Ready to Done
– Terminated by parent
• Blocked to Done
– Terminated by parent
running done

new ready blocked


5 State Model - Transitions

normal or abnormal termination

selected to running done

enter run
I/O
process created
request
quantum
expired
new ready blocked

I/O complete