CSC 4103 - Operating Systems Roadmap
Spring 2007
OS Design and Implementation
Lecture - III Different Design Approaches
- OS Design & Implementation Virtual Machines
- Processes Processes
Basic Concepts
Context Switching
Process Queues
Process Scheduling
Process Termination
Tevfik Koar
Louisiana State University
January 23rd, 2007 1 2
Operating System Design and Implementation Operating System Design and Implementation (Cont.)
Start by defining goals and specifications Important principle: to separate policies and
Affected by choice of hardware, type of system mechanisms
Batch, time shared, single user, multi user, distributed Policy: What will be done?
User goals and System goals Mechanism: How to do something?
User goals operating system should be convenient to use, easy Eg. to ensure CPU protection
to learn, reliable, safe, and fast
Use Timer construct (mechanism)
System goals operating system should be easy to design,
How long to set the timer (policy)
implement, and maintain, as well as flexible, reliable, error-
free, and efficient The separation of policy from mechanism is allows
No unique solution for defining the requirements of an maximum flexibility if policy decisions are to be
OS changed later
Large variety of solutions
Large variety of OS
3 4
OS Design Approaches Simple Structure
Simple Structure No well defined structure
Layered Approach Start as small, simple, limited systems, and then grow
Microkernels MS-DOS written to provide the most functionality in
Modules the least space
Not divided into modules
Its interfaces and levels of functionality are not well separated
e.g. application programs can access low level drivers directly
Vulnerable to errant (malicious) programs
5 6
1
UNIX
MS-DOS Layer Structure
UNIX limited by hardware functionality, the
original UNIX operating system had limited
structuring. The UNIX OS consists of two separable
parts
Systems programs
The kernel
Consists of everything below the system-call interface and
above the physical hardware
Provides the file system, CPU scheduling, memory
management, and other operating-system functions; a large
number of functions for one level
7 8
UNIX System Structure Layered Approach
The operating system is divided into a number of layers
(levels), each built on top of lower layers.
The bottom layer (layer 0), is the hardware;
The highest (layer N) is the user interface.
With modularity, layers are selected such that each
uses functions (operations) and services of only lower-
level layers
GLUnix: Global Layered Unix
9 10
Layered Operating System Microkernel System Structure
Move all non-essential components from the kernel into user
space
Main function of microkernel: Communication between client
programs and various services which are run in user space
Uses message passing (never direct interaction)
Benefits:
Easier to extend the OS
Easier to port the OS to new architectures
More reliable (less code is running in kernel mode)
More secure
Detriments:
Performance overhead of user space to kernel space communication
Examples: QNX, Tru64 UNIX
11 12
2
Modules Solaris Modular Approach
Most modern operating systems implement kernel
modules
Uses object-oriented approach
Each core component is separate
Each talks to the others over known interfaces
Each is loadable as needed within the kernel
Overall, similar to layers but more flexible
Any module can call any other module
13 14
Mac OS X Structure - Hybrid Virtual Machines
A virtual machine takes the layered approach
to its logical conclusion. It treats hardware
and the operating system kernel as though
they were all hardware
A virtual machine provides an interface
identical to the underlying bare hardware
The operating system creates the illusion of
multiple processes, each executing on its own
processor with its own (virtual) memory
BSD: provides support for command line interface, networking, file
system, POSIX API and threads
Mach: memory management, RPC, IPC, message passing
15 16
Virtual Machines (Cont.) Virtual Machines (Cont.)
The resources of the physical computer are shared to
create the virtual machines
CPU scheduling can create the appearance that users have their
own processor
Spooling and a file system can provide virtual card readers and
virtual line printers
A normal user time-sharing terminal serves as the virtual
machine operators console
Non-virtual Machine Virtual Machine
(a) Nonvirtual machine (b) Virtual machine
17 18
3
Virtual Machines (Cont.)
VMware Architecture
The virtual-machine concept provides complete
protection of system resources since each virtual
machine is isolated from all other virtual machines.
This isolation, however, permits no direct sharing
of resources.
A virtual-machine system is a perfect vehicle for
operating-systems research and development.
System development is done on the virtual
machine, instead of on a physical machine and so
does not disrupt normal system operation.
The virtual machine concept is difficult to
implement due to the effort required to provide an
exact duplicate to the underlying machine
19 20
The Java Virtual Machine
Processes
21 22
Process Concept Process State
As a process executes, it changes state
An operating system executes a new: The process is being created
variety of programs: running: Instructions are being executed
Batch system jobs
waiting: The process is waiting for some event to occur
Time-shared systems user programs
ready: The process is waiting to be assigned to a process
or tasks
terminated: The process has finished execution
Process a program in execution;
process execution must progress
in sequential fashion
A process includes:
program counter
stack: temporary data
heap: dynamic memory
data section: global variables
Process in Memory
23 24
4
Process Control Block (PCB) Context Switch
Information associated with each
When CPU switches to another process, the system
process
must save the state of the old process and load the
Process state saved state for the new process
Program counter Context-switch time is overhead; the system does no
CPU registers useful work while switching
CPU scheduling information Time dependent on hardware support
Memory-management
information
Accounting information
I/O status information
25 26
CPU Switch From Process to Process Process Scheduling Queues
Job queue set of all processes in the system
Ready queue set of all processes residing in main
memory, ready and waiting to execute
Device queues set of processes waiting for an
I/O device
Processes migrate among the various queues
27 28
Ready Queue And Various I/O Device Queues
Representation of Process Scheduling
29 30
5
Schedulers Schedulers (Cont.)
Short-term scheduler is invoked very frequently
Long-term scheduler (or job scheduler) (milliseconds) (must be fast)
selects which processes should be brought into Long-term scheduler is invoked very infrequently
the ready queue (seconds, minutes) (may be slow)
Short-term scheduler (or CPU scheduler) The long-term scheduler controls the degree of
selects which process should be executed next multiprogramming
and allocates CPU Processes can be described as either:
I/O-bound process spends more time doing I/O than
computations, many short CPU bursts
CPU-bound process spends more time doing computations;
few very long CPU bursts
long-term schedulers need to make careful decision
31 32
Addition of Medium Term Scheduling Process Creation
In time-sharing systems: remove processes from Parent process create children processes, which, in
memory temporarily to reduce degree of turn create other processes, forming a tree of
multiprogramming. processes
Later, these processes are resumed Swaping Resource sharing
Parent and children share all resources
Children share subset of parents resources
Parent and child share no resources
Execution
Parent and children execute concurrently
Parent waits until children terminate
33 34
Process Creation (Cont.) C Program Forking Separate Process
int main()
Address space {
Child duplicate of parent Pid_t pid;
Child has a program loaded into it /* fork another process */
pid = fork();
UNIX examples if (pid < 0) { /* error occurred */
fork system call creates new process fprintf(stderr, "Fork Failed");
exit(-1);
exec system call used after a fork to replace the process
}
memory space with a new program
else if (pid == 0) { /* child process */
execlp("/bin/ls", "ls", NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf ("Child Complete");
exit(0);
}
35 36
}
6
A tree of processes on a typical Solaris Any Questions?
sched: root process for OS
pageout: manages memory
fsflush: manages file system
init: root for user processes
inetd: Networking
Hmm..
Hmm..
dtlogin: user login screen
Unique process ids
37 38
Reading Assignment Acknowledgements
Read chapter 3 from Silberschatz. Operating Systems Concepts book and supplementary
material by Silberschatz, Galvin and Gagne.
39 40