CSC 150 Chapter 6: Operating Systems
primary information resource:
An Invitation to Computer Science (Java), Third Edition,
G. Michael Schneider and Judith L. Gersting,
Course Technology, 2007.
[ previous
| schedule
| next ]
Introduction
What is an operating system?
The answer to this question has led to many legal issues for Microsoft and the Justice Department (among others).
Do you consider your web browser part of the Windows OS?
Here’s an interesting definition: the one program running at all
times on the computer (from AOSC)
Another AOSC definition: program that acts as intermediary between a
user of a computer and the computer hardware
What does an OS do?
-
Controls execution of user programs
-
Controls operation of I/O devices
-
Makes efficient use of hardware resources
-
Makes the computer system easier to use (by providing a virtual machine
interface)
-
Protects system resources from misuse or abuse
On the surface: the user interface
The user interface allows you to work with system resources. Examples
I could demo in the classroom (but probably won't!) are:
- Windows XP
- Windows 98
- Mac OS
- DOS
- Linux
All are interactive, two are command-based and the rest are GUI.
Q: What kinds of things can you do from the user interface?
Historical review, from user interface perspective
The “prehistoric” era
-
No operating systems
-
Loader entered into memory manually using switches
(image of Data General's Nova 800 minicomputer)
-
Loader controlled input of machine language program from tape into memory
-
Program executed, normally input-compute-output
-
Output written to tape.
-
Computer idle between program runs
-
Machines to transfer program to tape and output to printer were separate.
- http://www.dvq.com/oldcomp/minis.htm has images of many types of early computing equipement
Batch Operating Systems
-
before PCs, most computers were mainframes
-
early mainframe operating systems were batch systems, not interactive.
-
Program run was called a job, and job was defined by a bundled sequence
of commands, program, and data.
-
Commands were written in job control language (JCL)
-
Typical sequence of a job:
-
$job card, with your name on it for identification
-
$respec (resource specification) cards, identifying the disk space required
-
$compile card identifying which assembler/compiler to use
-
Source code, your program
-
$load, link, and/or run card. What to do after compilation.
-
$data to signify beginning of data
-
Input data
-
$end card.
-
Early on, one job was loaded at a time and run to completion
-
Later, time-sharing OS allowed multiple jobs in memory simultaneously
Interactive command line operating systems
-
Started with early mini-computers
-
initially miniature version of early mainframes, exclusive use
-
OS user interface is command line interpreter (CLI).
-
CLI performs an endless loop of:
-
1. System issues command prompt
-
2. User types command followed by enter key
-
3. System interprets and carries out command
-
Familiar examples are MS-DOS, Unix.
Graphical User Interface (GUI) operating system
-
Started with Xerox PARC, Lisa, Macintosh.
-
Several design strategies:
- cover up command interface OS with GUI (X, Windows 3.1-95-98)
- integrated OS and GUI design (Mac through 9.x)
- hybrid (Mac OS-X)
-
Dominant interface metaphor is desktop.
-
Dominant interaction style is WIMP (Windows, Icons, Menus, Pointing
devices)
Peeking inside: Application Programmer Interfaces (API)
Libraries of functions and objects that application software programmer
uses to interface the application with the OS.
Win32 API is used for developing Windows applications usually in C.
-
Set of functions for creating and using GUI components (windows, menus,
etc).
-
MFC (Microsoft Foundation Classes) is a similar API oriented to C++ and
object-oriented technology.
Unix/Linux APIs geared toward C/C++ and focus more on interfacing with
OS internals
-
Process management (fork, exec, pipe)
-
Memory management (mmap)
-
File management (open, close, read, write)
-
Networking (socket, connect, bind)
API for writing applications in Java is conceptually OS-independent.
-
Process management focuses on threads
-
Classes for file management, networking
Under the surface: Operating System Internals
Major OS functions are:
-
Process management
-
Main memory management
-
File management
-
I/O device management
-
Protection
-
Networking
Process management
process is defined as a program in execution
a process is always in one of 5 states:
1. new (creation)
2. ready (can run but not assigned to processor)
3. running (executing)
4. waiting (waiting for external event)
5. terminated (finished execution)
Process starts in state 1, cycles among 2-3-4 and when finished jumps
to 5.
Goes from 1 to 2 when loaded into main memory
Goes from 2 to 3 when dispatcher assigns to processor
Goes from 3 to 4 when external event (e.g. I/O) requested
Goes from 4 to 2 when external event completed
Goes from 3 to 2 when time slice expires
Goes from 3 to 5 when finished.
Time slicing
-
some processes are I/O-bound and others are compute-bound.
-
If a compute-bound process could have exclusive use of CPU until completion,
other processes have to wait unfairly.
-
OS defines a time period, or time slice, to be the maximum amount of time
a process may have exclusive use of CPU.
-
I/O-bound processes loses exclusive use when I/O requested.
Scheduling
-
scheduler selects which process from among those in ready state will get
next time slice.
-
There are several possible strategies and several factors to consider.
Dispatching
-
dispatcher moves one process out of running state and another one in.
-
this process is called context switching
-
requires saving and resetting CPU register values.
Have to handle possibility of deadlock
-
Occurs when process 1 is holding resource A and waiting for resource B
while at the same time process 2 is holding resource B and waiting for
resource A. “the deadly embrace”
-
There are various strategies. E.g. can prevent this by forcing process
to release resource before requesting another one.
Have to gracefully handle interprocess communication
-
Processes may communicate with each other through shared memory
or message passing.
-
Shared memory can be a problem.
-
Suppose a buffer and counter C are shared between cooperating processes
1 and 2. C is count of values in the buffer.
-
Process 1 reads C and writes a value into the buffer.
-
Just before it increments C, the time slice expires.
-
Process 2 reads the (incorrect) value of C and writes a value into the
buffer, wiping out the value just written by process 1.
-
Note that incrementing C before writing to the buffer does not solve the
problem.
-
Each process requires mutually exclusive access to shared memory
for the duration of both operations (write to buffer, increment C)
-
There are various strategies for assuring it.
Main memory management
Ability to execute multiple processes concurrently is compromised unless
instructions/data for all can reside simultaneously in memory.
Major problems that result include:
-
Assembler produces machine code based on first instruction being in location
0. But only one process can actually occupy location 0 at a time,
the others will start at a non-zero address.
-
Each process requires a certain amount of memory. But the sum of
memory required for all current processes may exceed physical memory capacity.
-
When a process terminates, its memory is made available to other processes.
The total memory available may be large enough for the new process, but
is available only in several small chunks.
Problem 1 is easily dealt with in hardware. The CPU includes
a relocation register, which contains the physical starting location
of the currently executing machine code program. Its contents are
added to each memory fetch request before it goes into the MAR.
Problem 2 is dealt with by the use of virtual memory. Part
of the process is stored in physical memory and the rest in virtual memory
(on disk). When execution flows into an instruction in virtual memory,
the process must wait while that part of the program is read into physical
memory, possibly replacing parts of the program which have already executed.
Problem 3 is dealt with by organizing physical memory into small fixed
size pages and allowing a process to be stored across several non-adjacent
pages.
The solutions to problems 2 and 3 requires lots of OS tables and logic,
but the results are worth it.
File (secondary storage) management
Major issues are protection and allocation/de-allocation of disk space.
-
Disk space logically organized into small fixed size blocks (similar
to memory pages).
-
A file may be spread across several non-adjacent blocks.
-
Leads eventually to massive fragmentation.
-
Requires both a directory of files and a list of blocks for each file.
-
Protection handled through per-file descriptor that contains security information
used by OS protection mechanism.
I/O Device management
Major issues are:
-
Buffering and buffer coordination
-
Interrupts
-
Caching
(distinct from buffer: cache holds extra copy, while buffer holds the
only copy)
-
Interaction with device-specific drivers
Network management
Goal is to provide users a "single system image"
The virtual machine appears to be one physical machine but in fact is
multiple machines distributed across a network.
Network communication details are hidden from user (client)
Prime examples are interactions with file, print and email servers.
Protection and Security
A concern at all levels of the machine, OS, and operations (people)
-
Machine language includes privileged instructions available only to OS.
-
Processes execute in “kernel” (privileged) or “user” mode
-
Passwords must be encrypted
- Processes must not be allowed to access memory outside their bounds.
-
Different levels of file access must be maintained and enforced.
-
Networked machine must be shielded from viruses, worms, trojans, etc.
-
Etc.
[ C
SC 150 | Peter
Sanderson | Math Sciences server
| Math Sciences home page
| Otterbein ]
Last updated:
Peter Sanderson (PSanderson@otterbein.edu)