Professional Documents
Culture Documents
Operating Systems: Chapter 1: Introduction
Operating Systems: Chapter 1: Introduction
Chapter 1: Introduction
Homework: Read Chapter 1 (Introduction)
Homework: 1. (unless otherwise stated, problems numbers are from the end of the chapter in Tanenbaum.)
I cleaned up the lecture notes on the linker interlude. I suggest that those of you who heard the
recitation on wednesday, reread the lecture notes.
End of Note.
1.3.2: Files
Modern systems have a hierarchy of files. A file system tree.
• In MSDOS the hierarchy is a forest not a tree. There is no file, or directory that is an ancestor if both a:\ and c:\.
• In unix the existence of symbolic links weakens the tree to a DAG
Files and directories normally have permissions
• Normally have at least rwx.
• User, group, world
• More general is access control lists
• Often files have ``attributes'' as well. For example the linux ext2 filesystem supports a ``d'' attribute that is a hint to the dump program
not to backup this file.
• When a file is opened, permissions are checked and, if the open is permitted, a file descriptor is returned that is used for subsequent
operations
Devices (mouse, tape drive, cdrom) are often view as ``special files''. In a unix system these are normally found in the /dev directory. Often
utilities that are normally applied to (ordinary) files can be applied as well to some special files. For example, when you are accessing a unix
system using a mouse and do not have anything serious going on (e.g., right after you log in), type the following command
cat /dev/mouse
and then move the mouse. You kill the cat by typing cntl-C. I tried this on my linux box and no damage occurred. Your mileage may vary.
Many systems have standard files that are automatically made available to a process upon startup. These (initial) file descriptors are fixed
• standard input: fd=0
• standard output: fd=1
• standard error: fd=2
A convenience offered by some command interpretors is a pipe or pipeline. The pipeline
ls | wc
will give the number of files in the directory (plus other info).
1.4: OS Structure
I must note that Tanenbaum is a big advocate of the so called microkernel approach in which as much as possible is moved out of the
(supervisor mode) microkernel into separate processes.
In the early 90s this was popular. Digital Unix (now called True64) and Windows NT are examples. Digital Unix is based on Mach, a
research OS from Carnegie Mellon university. Lately, the growing popularity of Linux has called into question the belief that ``all new
operating systems will be microkernel based''.
Some systems have more layers and are more strictly structured.
An early layered system was ``THE'' operating system by Dijkstra. The layers were.
1. The operator
2. User programs
3. I/O mgt
4. Operator-process communication
5. Memory and drum management
The layering was done by convention, i.e. there was no enforcement by hardware and the entire OS is linked together as one program. This is
true of many modern OS systems as well (e.g., linux).
The multics system was layered in a more formal manner. The hardware provided several protection layers and the OS used them. That is,
arbitrary code could not jump to or access data in a more protected layer.
1.4.3: Virtual machines
Use a ``hypervisor'' (beyond supervisor, i.e. beyond a normal OS) to switch between
multiple Operating Systems
• Each App/CMS runs on a virtual 370
• CMS is a single user OS
• A system call in an App traps to the corresponding CMS
• CMS believes it is running on the machine so issues I/O instructions but ...
• ... I/O instructions in CMS trap to VM/370
When implemented on one computer, a client server OS is the microkernel approach in which the microkernel just supplies interprocess
communication and the main OS functions are provided by a number of separate processes.
This does have advantages. For example an error in the file server cannot corrupt memory in the process server. This makes errors easier to
track down.
But it does mean that when a (real) user process makes a system call there are more processes switches. These are not free.
A distributed system can be thought of as an extension of the client server concept where the servers are remote.
Homework: 11
Allan Gottlieb
Operating Systems
Chapter 2: Process Management
Tanenbaum's chapter title is ``processes''. I prefer process management. The subject matter is processes, process scheduling, interrupt
handling, and IPC (Interprocess communication--and coordination).
2.1: Processes
Definition: A process is a program in execution.
• We are assuming a multiprogramming OS that can switch from one process to another.
• Sometimes this is called pseudoparallelism since one has the illusion of a parallel processor.
• The other possibility is real parallelism in which two or more processes are actually running at once because the computer system is
a parallel processor, i.e., has more than one processor.
• We do not study real parallelism (parallel processing, distributed systems, multiprocessors, etc) in this course.
Process Hierarchies
Modern general purpose operating systems permit a user to create and
destroy processes.
• In unix this is done by the fork system call, which creates a child
process, and the exit system call, which terminates the current
process.
• After a fork both parent and child keep running (indeed they have
the same program text) and each can fork off other processes.
• A process tree results. The root of the tree is a special process
created by the OS during startup.
• A process can choose to wait for children to terminate. For
example, if C issued a wait() system call it would block until G
finished.
Old or primitive operating system like MS-DOS are not multiprogrammed
so when one process starts another, the first process is automatically
blocked and waits until the second is finished.
Process states and transitions
Let's try again. The trouble was that setting want before the loop permitted us to get stuck. We had them in the wrong order!
Initially P1wants=P2wants=false
This one forces alternation, so is not general enough. Specifically, it does not satisfy condition three, which requires that no process in its
non-critical section can stop another process from entering its critical section. With alternation, if one process is in its non-critical section
(NCS) then the other can enter the CS once but not again.
In fact, it took years (way back when) to find a correct solution. Many earlier ``solutions'' were found and several were published, but all
were wrong. The first true solution was found by Dekker. It is very clever, but I am skipping it (I cover it when I teach masters level OS II).
Subsequently, algorithms with better fairness properties were found (e.g., no task has to wait for another task to enter the CS twice).
What follows is Peterson's solution. When it was published, it was a surprise to see such a simple soluntion. In fact Peterson gave a solution
for any number of processes. A proof that the algorithm for any number of processes satisfies our properties (including a strong fairness
condition) can be found in Operating Systems Review Jan 1990, pp. 18-22.
Initially P1wants=P2wants=false and turn=1
satisfies
1. Mutual exclusion
2. No speed assumptions
3. No blocking by processes in NCS
4. Forward progress (my weakened version of Tanenbaum's last condition
Note that I use indenting carefully and hence do not need (and sometimes omit) the braces {}
A binary semaphore abstracts the TAS solution we gave for the critical section problem.
• A binary semaphore S takes on two possible values ``open'' and ``closed''
• Two operations are supported
• P(S) is
while (S=closed) {}
S<--closed <== This is NOT the body of the while
The only specific solution we have seen for an arbitrary number of processes is the one just above with P(S) implemented via test and set.
Remark: Peterson's solution requires each process to know its processor number. The TAS soluton does not. Moreover the definition of P
and V does not permit use of the processor number. Thus, strictly speaking Peterson did not provide an implementation of P and V. He did
solve the critical section problem.
To solve other coordination problems we want to extend binary semaphores.
• With binary semaphores, two consecutive Vs do not permit two subsequent Ps to succeed (the gate cannot be doubly opened).
• We might want to limit the number of processes in the section to 3 or 4, not always just 1.
The solution to both of these shortcomings is to remove the restriction to a binary variable and define a generalized or counting
semaphore.
• A counting semaphore S takes on non-negative integer values
• Two operations are supported
• P(S) is
while (S=0)
S--
loop forever
P(S)
SCS <== semi-critical-section
V(S)
NCS
Producer-consumer problem
• Two classes of processes
• Producers, which produce times and insert them into a buffer.
• Consumers, which remove items and consume them.
• What if the producer encounters a full buffer?
Answer: Block it.
• What if the consumer encounters an empty buffer?
Answer: Block it.
• Also called the bounded buffer problem.
• Another example of active entities being replaced by a data structure when viewed at a lower level (Finkel's level principle).
Initially e=k, f=0 (counting semaphore); b=open (binary semaphore)
Producer Consumer
Dining Philosophers
A classical problem from Dijkstra
• 5 philosophers sitting at a round table
• Each has a plate of spaghetti
• There is a fork between each two
• Need two forks to eat
What algorithm do you use for access to the shared resource (the forks)?
• The obvious solution (pick up right; pick up left) deadlocks.
• Big lock around everything serializes.
• Good code in the book.
The purpose of mentioning the Dining Philosophers problem without giving the solution is to give a feel of what coordination problems are
like. The book gives others as well. We are skipping these (again this material would be covered in a sequel course). If you are interested
look, for example, here.
Homework: 14,15 (these have short answers but are not easy).
Deadline scheduling
This is used for real time systems. The objective of the scheduler is to find a schedule for all the tasks (there are a fixed set of tasks) so that
each meets its deadline. The run time of each task is known in advance.
Actually it is more complicated.
• Periodic tasks
• What if we can't schedule all task so that each meets its deadline (i.e., what should be the penalty function)?
• What if the run-time is not constant but has a known probability distribution?
We do not cover deadline scheduling in this course.
Priority Scheduling
Each job is assigned a priority (externally, perhaps by charging more for higher priority) and the highest priority ready job is run.
• Similar to ``External priorities'' above
• If many processes have the highest priority, use RR among them.
• Can easily starve processes (see aging below for fix).
• Can have the priorities changed dynamically to favor processes holding important resources (similar to state dependent RR).
• Many policies can be thought of as priority scheduling in which we run the job with the highest priority (with different notions of
priority for different policies).
Priority aging
As a job is waiting, raise its priority so eventually it will have the maximum priority.
• This prevents starvation (assuming all jobs terminate). policy is preemptive).
• There may be many processes with the maximum priority.
• If so, can use fifo among those with max priority (risks starvation if a job doesn't terminate) or can use RR.
• Can apply priority aging to many policies, in particular to priority scheduling described above.
Homework: 22, 23
Theoretical Issues
Considerable theory has been developed.
• NP completeness results abound.
• Much work in queuing theory to predict performance.
• Not covered in this course.