Class Note in O.S

  • View

  • Download

Embed Size (px)

Text of Class Note in O.S

Web PagesThere is a web page for the course. You can find it from my home page.

Can find these notes there. Let me know if you can't find it. They will be updated as bugs are found. Will also have each lecture available as a separate page. I will produce the page after the lecture is given. These individual pages might not get updated.

TextbookText is Tanenbaum, "Modern Operating Systems".

Available in bookstore. We will do part 1, starting with chapter 1.

Computer Accounts and Mailman mailing list

You are entitled to a computer account, get it. Sign up for a Mailman mailing list for the course. If you want to send mail to me, use not the mailing list. You may do assignments on any system you wish, but ... o You are responsible for the machine. I extend deadlines if the nyu machines are down, not if yours are. o Be sure to upload your assignments to the nyu systems. If somehow your assignment is misplaced by me or a grader, we need a to have a copy ON AN NYU SYSTEM that can be used to verify the date the lab was completed. When you complete a lab (and have it on an nyu system), do not edit those files. Indeed, put the lab in a separate directory and keep out of the directory. You do not want to alter the dates.


Homework and LabsI make a distinction between homework and labs. Labs are

Required Due several lectures later (date given on assignment) Graded and form part of your final grade Penalized for lateness

Homeworks are:

Optional Due the beginning of Next lecture Not accepted late Mostly from the book Collected and returned Can help, but not hurt, your grade

Upper left board for assignments and announcements.

Interlude on LinkersOriginally called linkage editors by IBM. This is an example of a utility program included with an operating system distribution. Like a compiler, it is not part of the operating system per se, i.e. it does not run in supervisor mode. Unlike a compiler it is OS dependent (what object/load file format is used) and is not (normally) language dependent.


What does a Linker Do?Link of course. When the assembler has finished it produces an object module that is almost run able. There are two primary problems that must be solved for the object module to be runnable. Both are involved with linking (that word, again) together multiple object modules.1. Relocating relative addresses.o o o


Each module (mistakenly) believes it will be loaded at location zero (or some other fixed location). We will use zero. So when there is an internal jump in the program, say jump to location 100, this means jump to location 100 of the current module. To convert this relative address to an absolute address, the linker adds the base address of the module to the relative address. The base address is the address at which this module will be loaded. Example: Module A is to be loaded starting at location 2300 and contains the instructionjump 120

The linker changes this instruction tojump 2420 o o o o o

How does the linker know that Module M5 is to be loaded starting at location 2300? It processes the modules one at a time. The first module is to be loaded at location zero. So the relocating is trivial (adding zero). We say the relocation constant is zero. When finished with the first module (say M1), the linker knows the length of M1 (say that length is L1). Hence the next module is to be loaded starting at L1, i.e., the relocation constant is L1. In general the linker keeps track of the sum of the lengths of all the modules it has already processed and this is the location at which the next module is to be loaded.


2. Resolving external references.o

If a C (or Java, or Pascal) program contains a function callf(x)

o o o o

to a function f() that is compiled separately, the resulting object module will contain some kind of jump to the beginning of f. But this is impossible! When the C program is compiled. the compiler (and assembler) do not know the location of f() so there is no way it can supply the starting address. Instead a dummy address is supplied and a notation made that this address needs to be filled in with the location of f(). This is called a use of f. The object module containing the definition of f() indicates that f is being defined and gives its relative address (which the linker will convert to an absolute address). This is called a definition of f.

The output of a linker is called a load module because it is now ready to be loaded and run. To see how a linker works lets consider the following example, which is the first dataset from lab #1. The description in lab1 more detailed. The target machine is word addressable and has a memory of 1000 words, each consisting of 4 decimal digits. The first (leftmost) digit is the opcode and the remaining three digits form an address. Each object module contains three parts, a definition list, a use list, and the program text itself. Each definition is a pair (sym, loc). Each use is a pair (sym, loc). The address in loc points to the next use or is 999 to end the chain. For those text entries that do not form part of a use chain a fifth (leftmost) digit is added. If it is 8, the address in the word is relocatable. If it is 0 (and hence omitted), the address is absolute. is


Sample input 1 xy 2 1 z 4 5 10043 56781 29994 80023 70024 0 1 z 3 6 80013 19994 10014 30024 10023 10102 0 1 z 1 2 50013 49994 1 z 2 1 xy 2 3 80002 19994 20014

I will illustrate a two-pass approach: The first pass simply produces the symbol table giving the values for xy and z (2 and 15 respectively). The second pass does the real work (using the values in the symbol table). It is faster (less I/O) to do a one pass approach, but is harder since you need ``fix-up code'' whenever a use occurs in a module that precedes the module with the definition.xy=2 z=15 +0 0: 1: 2: xy: 3: 4: ->z +5 0 1 2 3 ->z 10043 56781 29994 80023 70024 80013 19994 10014 30024 1004+0=1004 5678 2015 8002+0=8002 7015 8001+5=8006 1015 1015 3015


->z ->z


4 5 +11 0 1 ->z +13 0 1 2 z:->xy

10023 10102 50013 49994 80002 19994 20014 ->xy

1002+5=1007 1010 5001+11=5012 4015 8000 1002 2002

The linker on UNIX is mistakenly called ld (for loader), which is unfortunate since it links but does not load. Lab #1: Implement a linker. The specific assignment is detailed on the sheet handed out in in class and is due in two weeks, 2 October 2000 . The content of the handout is available on the web as well (see the class home page).

Chapter 1. IntroductionLevels of abstraction (virtual machines)

Software (and hardware, but that is not this course) is often implemented in layers. The higher layers use the facilities provided by lower layers. Alternatively said, the upper layers are written using a more powerful and more abstract virtual machine than the lower layers. Alternatively said, each layer is written as though it runs on the virtual machine supplied by the lower layer and in turn provides a more abstract (pleasent) virtual machine for the higher layer to run on. Using a broad brush, the layers are. 1. Scripts (e.g. shell scripts) 2. Applications and utilities


3. Libraries 4. The OS proper (the kernel) 5. Hardware The kernel itself is itself normally layered, e.g. 1. ... 2. File systems 3. Machine independent I/O 4. Machine dependent device drivers The machine independent I/O part is written assuming ``virtual (i.e. idealized) hardware''. For example, the machine independent I/O portion simply reads a block from a ``disk''. But in reality one must deal with the specific disk controller. Often the machine independent part is more than one layer. The term OS is not well defined. Is it just the kernel? How about the libraries? The utilities? All these are certainly system software but not clear how much is part of the OS.

1.1: What is an operating system?The kernel itself raises the level of abstraction and hides details. For example a user (of the kernel) can write to a file (a concept not present in hardware) and ignore whether the file resides on a floppy, a CD-ROM, or a hard magnetic disk The kernel is a resource manager (so users don't conflict). How is an OS fundamentally different from a compiler (say)? Answer: Concurrency! Per Brinch Hansen in Operating Systems Principles (Prentice Hall, 1973) writes. The main difficulty of multiprogramming is that concurrent activities can interact in a time-dependent manner, which makes it practically impossibly to locate programming errors by systematic testing. Perhaps, more than anything else, this explains the difficulty of making operating systems reliable.


1.2 History of Operating Systems1. Single user (no OS). 2. Batch, uniprogrammed, run to completion. o The OS now must be protected from the user program so that it is capable of starting (and assisting) the next program in the batch). 3. Multiprogrammed o The purpose was to overlap CPU and I/O o Multiple batches IBM OS/MFT (Multiprogramming with a Fixed number of Tasks) The (real) memory is partitioned and a batch is assigned to a fixed partition. The memory assigned to a partition does not change IBM OS/MVT (Multiprogramming with a Variable number of Tasks) (then other names) Each job gets just the amount of memory it needs. That is, the partitioning of memory changes as jobs enter and leave MVT is a more ``efficient'' user of resources but is more difficult. When we study memory management, we will see that with varying size partitions questions like compaction and ``holes'' arise. o Time sharing This is multiprogramming with rapid switching between jobs (p