Title: Operating Systems
1Operating Systems
- Shyh-Kang Jeng
- Department of Electrical Engineering/
- Graduate Institute of Communication Engineering
- National Taiwan University
2Operating Systems
- Interface between a user and the computer
hardware - Provide an environment in which a user can
execute programs - Goals
- Make the computer system convenient to use
- Use the computer hardware (resources) in an
efficient manner
3Batch Processing
Especially suitable for payroll processing
4Interactive Processing
5Real-Time Processing and Time-Sharing Systems
- Real-time processing
- Processing whose response time is restricted
- Time-sharing systems
- Shuffle jobs by dividing time into intervals
- Multitasking for a one-user system
- Efficient than the sequential way especially for
jobs which must wait for peripheral devices
6Multiprocessor Systems
- Sharing information and resources among different
machines - Networks
- Coupled computer systems
- Software controlling a network is as a
network-worldwide operating system - Load balancing
- Dynamically allocate tasks to various processes
so that all processors are used efficiently - Scaling
- Break tasks into a number of subtasks compatible
with the number of processors available
7Scalability
- Capability of a system to adapt to increased
service load - A scalable system reacts more gracefully to
increased load than does a non-scalable one - A scalable system has the potential to grow
without problems like generating additional
indirect load on other resources or incurring
design modification
8Application and System Software
- Application software
- Performs tasks particular to the machines
utilization - System software
- Performs tasks common to computer system in
general - OS utility software
- Utility software
- Collection of software units extending the
capabilities of OS
9Software Classification
10Shells
11Shells
- Portion of an OS to define the interface between
the OS and its users - Types of shells
- Textual interface
- e.g., Borne shell, C shell, Korn shell in Unix
MS-DOS for Microsoft Windows - Graphical user interface
- e.g., WinXP, Mac
- Window manager
12Kernels
- Performs the very basic functions required by the
computer installation - Main components
- File manager
- Device drivers
- Memory manager
- Scheduler and dispatcher
13File Manager
14File Systems
- Directory or folder
- Path C\animals\prehistoric\dinosaurs
- Any access to a file by other software units is
obtained at the discretion of the file manager - File descriptor
- Information needed to find and manipulate the file
15Device Drivers
16Device Drivers
- Software units that communicate with the
controllers to carry out operations on the
peripheral devices attached to the machine - Each device driver is uniquely designed for its
particular type of device - Example Device driver for a printer contains
software to read and decode status word as well
as other handshaking details. Other software
does not have to deal with those technicalities
in order to print a file - A generic OS can be customized for particular
peripheral devices by merely installing
appropriate device drivers
17Memory Manager
- Charged with the tasks of coordinating the
machines use of main memory - Such duties are extensive in multi-user or
multitasking environments - Many programs and blocks of data reside in main
memory concurrently - Must find places to fulfill memory requirements
and keep track of memory areas no longer occupied
18Virtual Memory
- Illusion of additional memory space by rotating
programs and data back and forth between main
memory and mass storage - Useful when total main memory space required
exceeds the space actually available in the
machine - Divides the required space into units called
pages and stores these pages in mass storage - Memory manager exchange pages required in memory
for pages that are no longer required - Other software units can execute as though there
were large main memory in the machine
19PC Memory Manager
- 4 GB addressable
- space for 32-bit
- addressing
- Virtual memory
- Page
- Page fault
Mass Storage
20Scheduler and Dispatcher
- Scheduler
- Determines which activities are to be considered
for execution in a time-sharing system - Dispatcher
- Controls the allocation of time slices to the
scheduled activities
21Boot Strapping (Booting)
- Procedure performed by the machine each time it
is turned on - Read-only memory (ROM) vs. Random access memory
(RAM) - A small part of the main memory is constructed
from ROM - Bootstrap program is stored in ROM and executed
automatically when the machine is turned on
22Bootstrap Program
- Directs the CPU to transfer material from a
predetermined location in mass storage into the
volatile area of main memory - In most cases this material is the operating
system - Once the operating system has been placed in main
memory, the bootstrap program directs the CPU to
execute a jump to that area of memory - At this point, the operating system takes over
and begins controlling the machines behavior
23Booting Process
24Bootstrap in Personal Computers
- Try to extract the operating system from a floppy
disk first - If no such disks are found, the bootstrap will
automatically try to extract the operating system
from the machines hard disk - If floppy disk is inserted, and that disk does
not contain a copy of the operating system, the
bootstrap will pause with an error message to the
machines operator
25Concept of Process
- Program
- A static set of directions (passive entity)
- Process
- Program (application and utilities) in execution
(active entity) - Needs resources to accomplish its task
- Resources are given to the process when created
- Can be executed in parallel
- A single program can be associated with more than
one process, each with its own data and rate of
progress
26Process Administration
- Handled by scheduler and dispatcher within kernel
- Scheduler
- Maintains a process table
- Dispatcher
- Ensures the scheduled processes are actually
executed - Time slice (or quantum) typically no more than
50 milliseconds - Process switch
27Process Table
- Record of the process present in the computer
system - Contains information of
- Memory area assigned to the process
- Priority of the process
- Status of the process
- Ready can continue
- Waiting currently delayed until some external
event occurs
28Program and Processes
29Processes in Windows
30Time-Sharing Between Processes
31Process Switch
- The procedure of changing from one process to
another - Occurs when an interrupt signal is generated at
the end of the quantum - Process state of an executing process is saved
and the process becomes idle - Interrupt is handled by interrupt handler
- Process state of the process to be executed next
is loaded - The new process starts running
32Process State
- A snapshot of the machine at that time
- Defined by its current activity
- Includes program counter, values in CPU registers
and associated memory cells, etc. - Changes as a process executes
new
ready
running
halted
waiting
33Interrupt Handler
- Part of the dispatcher
- Preempt the current process and transfer control
back to the dispatcher - At this point, the dispatcher allows the
scheduler to update the process table (e.g.,
changing priorities) - The dispatcher then selects the process from the
process table that has the highest priority among
ready process - Restarts the timer circuit, and allow the
selected process to begin its time slice
34Terminating a Time Slice Early
- For example, if a process executes an I/O
request, the time slice of that process will be
terminated - The scheduler will update the process table to
reflect the processs waiting status - The dispatcher will assign a new quantum to a
process that is ready - When the controller indicates that I/O request
has been completed, the scheduler will reclassify
the process as ready, and the process will again
compete for a time slice
35Mini Review
- If each quantum in a time-sharing system is 50
milliseconds and each context switch requires at
most a microsecond, how many processes can the
machine service in a single second? - If each process uses its complete quantum in the
machine in last question, what fraction of the
machines time is spent actually performing
process? What would this fraction be if each
process executes an I/O request after only a
microsecond of its quantum?
36Answer
- If each process consumed its entire time slice,
the machine could provide a complete quantum to
almost 20 processes in one second. If processes
did not consume their entire time slices, this
value could be much higher, but then the time
required to perform a context switch may become
more significant
37Answer (continue)
- A total of 5000/5001 of the machines time would
be spent actually performing processes. However,
when a process requires an I/O activity, its time
slice is terminated while the controller performs
the request. Thus if each process made such a
request after only one microsecond of its
quantum, the efficiency of the machine would drop
to ½.
38Threads
Thread
Thread
Thread
Thread
CPU
Thread
Thread
Thread
Thread
Thread
Thread
Thread
Thread
J. Richter ??, ?????, Microsoft Windows
??????????, ??, 2001
39Interprocess Communication
- To coordinate activities of processes
- For examples,
- Scheduling a new process the scheduler must
obtain memory space from the memory manager - Accessing a file in mass storage the process
must first obtain information from the file
manager
40Client/Server Model forInterprocess Communication
41Client/Server Model
- Client makes requests
- Server satisfies the requests made by clients
- Simplifies inter-process communications
- To gain uniformity among all types of
communication taking place in the system, no
matter they are at the same machine or different
machines
42Client-Server Communications
43Communications between Software
44Common Object Request Broker Architecture (CORBA)
45Allocation of Resources
- An important task of an operating system is the
allocation of resources to the processes in the
system - Resources machines peripheral devices as well
as features within the machine - Access to files and disk space (file manager)
- Memory space (memory manager)
- Space in process table (scheduler)
- Time slices (dispatcher)
46Competition among Processes
- Two alternatives
- Disable interrupt in test and set
- Test and set as a single instruction
47Competition for Resources
- Assume a process needs to print
- Request the OS to give it access to the printers
device driver - OS decide whether to grant the request, depending
upon whether the printer is already being used by
another process - If the printer is used by another process, the OS
should deny the request and classify the process
as waiting until the printer is ready - If two processes were given simultaneous access
to printer, the results would be worthless to both
48Using Flag to Control Access
- OS must keep track of whether the printer has
been allocated - Use a flag (a bit in memory) as set or clear to
indicate that the printer is currently allocated
or not - Testing and possibly setting the flag requires
several machine instructions
49A Possible Problem in the Flag Approach
Process 2
OS
Printer Device Driver
Process 1
Check flag
Request for printer
Grant access to printer
clear
Interrupt process
Check flag
Request for printer
clear
Grant access to printer
Set flag
Access printer
Resume process
Access printer
50Two Solutions
- Use the interrupt disable and interrupt enable
instructions provided in most machine language - When OS starts the flag-testing routine, it
disables the interrupt, and ends it by enabling
the interrupt - Use the test-and-set instruction available in
many machine language - Direct the CPU to retrieve the flag, note the
value received, and set the flag, all within a
machine instruction
51Semaphores
- Properly implemented flag
52Critical Region and Mutual Exclusion
???, Visual C 6 ????????, ????, 1999.
53Critical Region and Mutual Exclusion
- Critical region A sequence of instructions that
executed by only one process at a time - Mutual exclusion Requirement that only one
process at a time to execute a critical region
54Examples of Deadlock
- One process has access to printer but is waiting
for tape drive, while another process has access
to tape drive but is waiting for printer - Scheduler has no space left in the process table
and each process in the system must create an
additional process before it can complete its task
55Deadlock
- A situation that two or more processes are
blocked from processing because each is waiting
for access the resources allocated to another - Degrade systems performance
- Deadlock handling
- Prevention
- Avoidance
- Detection and correction
56Deadlock
57Prerequisites of Deadlock
- Competition for non-sharable resources
- Resources are requested on a partial basis
- Once a resource has been allocated, it can not be
forcibly retrieved
58Removing Deadlocks
- Deadlock detection and correction schemes
- Requiring each process to request all the
resources at one time - Converting non-shareable resources into shareable
ones
59Examples of Removing Deadlock
- If deadlock occur due to a full process table,
the administrator merely uses his powers to
remove (kill) some of the process - Spooling holding data for output at a later but
more convenient time - Each time a process requires the printer, the OS
grants the request. However, OS connects the
process to a device that stores the information
to be print on a disk - When the printer is available, OS transfers the
data from the disk to printer
60Mini Review
- Suppose the following solutions have been
proposed for removing the deadlock that occurs on
a single-lane bridge when two cars meet.
Identify which condition for deadlock is removed
by each solution - Do not let a car onto the bridge until the bridge
is empty - If cars met, make one of them back up
- Add a second lane to the bridge
61Answer
- This guarantees that the non-shareable resource
is not required and allocated on a partial basis - This means that the non-shareable resource can be
forcibly retrieved - This makes the non-shareable resource shareable,
which removes the competition
62Another Competition Problem
- A file manager could grant several processes
access to the same file if the processes merely
read data - Conflicts occur if more than one process tries to
alter a file at the same time - File manager may allow only one process have
write access at any given time - Other systems divide the file into pieces so that
different processes can alter different parts of
the file concurrently
63Security from outside attacks
- Most common protection require user name and
password - Problem password stealing
- Problem automated password guessers
- Countermeasures
- Always tell user when he/she last logged in
- Report repeated bad guesses
- Log the guesser into a captive account to spy on
the guesser
64Security from attacks from within
- Operating system prevents illegal access to
resources - Different memory for different processes
- Privileged instructions only allowed in kernel
- All file access passes through the kernel
- Other devices can only be accessed through the
kernel
65Homework 3
- 4, 7, 10, 11, 14, 18, 25, 29, 31, 37, 41