Title: Lecture 3: OS Functions and Design Approaches
1Lecture 3 OS Functions and Design Approaches
- OS duties
- process management
- memory management
- disk/file management
- protection security
- interaction with OS
- dual-mode operation
- system calls
- API, system programs, UI
- OS design approaches
- monolithic kernel
- microkernel
- virtual machine
2Process Management
- OS manages many kinds of activities
- user programs
- system programs printer spoolers, name servers,
file servers, etc. - a running program is called a process
- a process includes the complete execution context
(code, data, PC, registers, OS resources in use,
etc.) - a process is not a program
- program - a sequence of instructions (passive)
- process - one instance of a program in execution
(active) - many processes can be running the same program
and one program may cause to create multiple
processes - from OS viewpoint process is a unit of work OS
must - create, delete, suspend, resume, and schedule
processes - support inter-process communication and
synchronization, handle deadlocks
3Memory Management
- primary (main) memory (RAM)
- provides direct access storage for CPU
- processes must be in main memory to execute
- OS must
- mechanics
- keep track of memory in use
- keep track of unused (free) memory
- protect memory space
- allocate, deallocate space for processes
- swap processes memory ? disk
- policies
- decide when to load each process into memory
- decide how much memory space to allocate to each
process - decide when a process should be removed from
memory
4Disk Management
- the size of the disk is much greater than main
memory and, unlike main memory, disk is
persistent (endures system failures and power
outages) - OS hides peculiarities of disk usage by managing
disk space at low level - keeps track of used spaces
- keeps track of unused (free) space
- keeps track of bad blocks
- OS handles low-level disk functions, such as
- schedules of disk operations
- and head movement
5File Management
- disks provide long-term storage, but are awkward
to use directly - file - a logical named persistent collection of
data maintained by OS - file system - a logical structure that that is
maintained by OS to simplify file manipulation
usually directory based - OS must
- create and delete files and directories
- manipulate files and directories - read, write,
extend, rename, copy, protect - provide general higher-level services - backups,
accounting, quotas - note the difference between disk management and
file system management
6Protection Security
- protection any mechanism for controlling access
of processes or users to resources - disk, memory, CPU,
- security defense of the system against internal
and external attacks - systems generally first distinguish among users,
to determine who can do what - user identities and privileges associated with
this identifier - user ID then associated with all files, processes
of that user to determine access control
7Dual-Mode Operation
- to allow protection OS operates in dual-mode
- user mode and kernel mode
- mode bit provided by hardware
- user (1), kernel (0)
- enables OS to distinguish when system is running
user code or kernel code - some instructions designated as privileged, only
executable in kernel mode - changing modes
- modifying timers
- modifying interrupt service routines
- I/O device access
8System Call Definition
- app. program can ask the OS to carry out service
forit by invoking a system call - to the application the invocation is similar to
an ordinary function call - example Unix write system call description
prompt man -S 2 write WRITE(2)
Linux Programmer's Manual
WRITE(2) NAME write - write to a file
descriptor SYNOPSIS include ltunistd.hgt
ssize_t write(int fd, const void buf,
size_t count) DESCRIPTION write()
writes up to count bytes to the file referenced
by the file descriptor fd from the buffer
starting at buf. RETURN VALUE On
success, the number of bytes written are returned
9Mode Switch
- mode switch transition from user to kernel mode
- system call generates a trap (software
generatedinterrupt) - physical interrupt occurs (e.g. a timer
interrupt) - control is transferred to the interrupt service
routine, which may pass control to the OS (in
kernel mode) return it back to the user process - in case OS needs to do extensive work, it needs
to save the context (state) of the user program
10Function Invocation TraceAcross Modes
- Example function invocation in Solaris (Unix-like
OS from Sun Microsystems) - node the mode (User or Kernel) for function
invocation
11System Call Example
- a typical app. program invokes system calls
repeatedly - example copying a file
12 Application Program Interface
- raw system calls tend to be difficult to use
- application program interface (API) defines
functions that are more convenient to use - API functions
- can be invoked by app. programmer
- run in user mode
- directly invoke system calls
- implemented in system libraries that come with
the OS and are linked to the app. program - API examples POSIX API (implemented by most Unix
systems, MacOS X), Java API, Win 32 API windows - ex printf (C function that prints formatted
output, part of POSIX API) repeatedly invokes
write
13 System Programs and UIs
- system programs come with the OS
- they are designed for end users the personfor
whom the computer/OS/app. programs are designed - cf. application programmers, OS programmers
- operate in user mode
- typical tasks file manipulation, status info,
file modification (editors), programming language
support (compilers/assemblers), configuration,
communication, etc. - user interface (UI) is a way the end-user
interacts with system programs (and through them
with the OS), - command-line interface (CLI) interaction
through command interpreter (shell) a
text-based system program - graphical-user interface (GUI) mouse-heavy with
a lot of graphics - most popular OSes support both kinds of UI
14Monolithic Kernel OS Design
critical OS data structures and device registers
are protected from user programs
- advantages speed and ease of operation
(everything is at hand) - disadvantages
- hard to develop, maintain, modify and debug
- kernel gets bigger as the OS develops
15Microkernel
- small kernel implements communication (usually
messages) - when system services are required microkernell
calls other parts of OS running in user modes and
passes the request there
- advantages reliability, ease of development,
modularity - parts can be replaced and tailored
to the architecture, user requirements etc. - disadvantages slow?
- examples MacOS X, Windows XP
16Virtual Machine
- OSs system callsare considered an enhancement
ofhardwaresinstruction set - extend further virtual machine
- each user task is provided with an abstract
(virtual machine) which OS hardware implement - IBM pioneered
- Java VM modern example
- adv. portability at binary-level, security,
greater language flexibility - dis. speed(?)
17Java Virtual Machine (JVM)
- Java source code is translated into an
architectureindependent java bytecode - bytecode is executed by JVM
- JVM can be implemented purely in software or in
hardware - JVM verifies bytecodes correctness and then
either interprets (translates the code into
machines instructions one by one) - or just-in-time (JIT) compiles to optimize, or
both - adv. portability at binary-level, security,
greater language flexibility - dis. speed(?)
18Lecture Review
- major OS duties are
- process management
- memory management
- disk/file management
- OS interacts with users through system calls, to
ease interaction - API - for app. programmers
- GUI or CLI for end-users
- OS is a big and complex program traditional
monolithic kernel design approach yields OSes
that are fast but hard to develop, modify and
debug other approaches have been suggested - microkernel
- virtual machine
19Future network computers?
- JavaOS
- no disk
- OS is only capable of running Java Virtual
Machine - all the programs (including OS components) are
downloaded over the network - advantages ease of administration and rollout
(installation), platform independence - disadvantages ??
20Monolithic Kernel OS Design
critical OS data structures and device registers
are protected from user programs can use
privileged instructions
- advantages speed and ease of operation
(everything is at hand) - disadvantages
- hard to develop, maintain, modify and debug
- kernel gets bigger as the OS develops
21Layered Design
- divide OS into layers
- each layer uses services provided by next lower
layer yet the implementation of these services
are hidden from the upper layer - THE Operating system layer structure
- user programs
- buffering for input and output devices
- operator-console device driver
- memory management
- CPU scheduling
- hardware
- advantages easier development and implementation
- disadvantages not always easy to break down on
layers, slower (each level adds overhead) - ex CPU scheduler is lower than virtual memory
driver (driver may need to wait for I/O) yet the
scheduler may have more info than can fit in
memory - examples THE, OS/2