• Runs on a variety of computers, from notebooks to Lecture 17 supercomputers • Dominant operating system for high-end workstations and servers Case Study • It was carefully designed to be simple • In spite of its age it is still modern and elegant Unix • Many design principles came with, or from Unix • Many of these design principles have been copied by other systems • Many versions: BSD, AIX, HPUX, Linux, Solaris, etc.
1 2
UNIX - History UNIX - History
• 60s - general-purpose timesharing • Unix in a high-level language – MIT: CTSS – It was hard to rewrite Unix for each different – MIT, Bell Labs, and General Electric: MULTICS machine – Bell Labs left – Languages available were not appropriate • Ken Thompson decided to write its own system in • CPL – BCPL – tag">B assembler to run on a PDP-7 • This system, UNICS, a smaller version of MULTICS, – Ritchie designed C and wrote a compiler for it was later called UNIX – Thompson and Ritchie rewrote UNIX in C • Dennis Ritchie and other people joined the project – C became the standard language for systems since • UNIX was ported to other, more powerful, PDP machines, (with 256KB and 2MB of memory) with then memory protection
3 4
UNIX - History UNIX Overview
• Unix got known – In 1974, Ritchie and Thompson published a • Interactive system landmark paper about UNIX • Designed to handle multiple processes and – In 1984, Ritchie and Thompson were given a Turing mutliple users at the same time award for the work described in that paper • Designed by programmers for programmers – After the publication of that paper, universities • System is expected to be simple, elegant, and started asking for a copy of UNIX consistent – Bell Labs (part of AT&T by then) was not permitted – Files should be just a collection of bytes in the computer business – Command should accept parameters in the same way – Bell Labs started licensing UNIX to universities for – The commands’ interface should be simple a small fee
5 6
1 UNIX Overview UNIX Kernel
User Interface • The layers of a UNIX system.
Approximate structure of generic UNIX kernel Interfaces and layers in a UNIX system
7 8
The UNIX Shell Processes in UNIX
• The shell is a command line interface • Processes are the only active entities in a • UNIX does support a graphical environment (X UNIX system Windows) • In comparison with graphical interfaces, the shell • Processes run sequentially is more powerfull, faster to use, and easily • Processes can create additional threads extensible • UNIX is a multiprogramming system • Some examples – ch, csh, ksh, bash – Multiple independent processes may be running • The shell accepts command lines and starts at the same time processes to execute the corresponding commands
9 10
Processes in UNIX Processes in UNIX
• Daemon (background) processes are always • Processes are created by a system call, fork running • The child is an exact independent copy of – Handle incoming and outgoing email the parent – Manage the printer queue • The child may turn itself into another – Check if there are enough free pages in memory process by executing a system call exec – Etc.
11 12
2 Processes in UNIX Processes in UNIX
• Processes can comunicate through a channel • Processes can comunicate through signals called pipe • A process can send a signal to another • A process sends a stream of bytes to another process process through the pipe • A process can define what is supposed to be • Synchronization is possible because the done when a specific signal is received receiver process blocks waiting for data
13 14
POSIX Shell The ls Command
A highly simplified shell Steps in executing the command ls type to the shell
15 16
UNIX Scheduler UNIX Scheduler
• Designed to provide good response to • Each version has a slightly different scheduling interactive systems algorithm close to the generic one • 2-level algorithm • Generic low-level – Multiple queues – The low-level algorithm picks the process to – Each queue associated with a range of priorities run next – Processes executing in user mode have positive values – The high-level algorithm moves processes – Processes executing in kernel mode have negative values between memory and disk – Negative values have higher priorities – Only processes that are in memory are in the queues
17 18
3 UNIX Scheduler UNIX Scheduler
• Generic low-level – The scheduler searches the queues starting at the highest priority – The first process found is dispatched – A process runs until it blocks or for 100msec (typically) – If a process uses its quantum, it is placed at the end of the queue – Once a second, each process’ priority is recalculated priority = CPU-usage + nice + base – Idea: get processes out of the kernel fast The UNIX scheduler is based on a multilevel queue structure 19 20
Memory Management Memory Management
• Memory model is straightforward • Fundamental concepts • Goal – Address space with 3 segments – Programs should be portable • Text segment – read only • Data segment – System may run on machines with widely – Initialized and unitialized data (BSS) differing memory management units • Stack segment • Has barely changed in decades • Works really well and has not needed much revision
21 22
Handling Memory Sharing Files
Process A Process B Two processes can share a mapped file.
• Process A's virtual address space • Physical memory • Process B's virtual address space A new file mapped simultaneously into two processes 23 24
4 Paging in UNIX UNIX I/O (2)
The core map in 4BSD.
The core map has an entry for each page The UNIX I/O system in BSD 25 26
Streams The UNIX File System (2)
• Before linking. • After linking.
An example of streams in System V (a) Before linking. (b) After linking 27 28
The UNIX File System (3) UNIX File System (1)
• Separate file systems • After mounting
Disk layout in classical UNIX systems (a) (b) (a) Before mounting. (b) After mounting 29 30
5 UNIX File System (2) UNIX File System (3)
Directory entry fields.
The relation between the file descriptor table, the Structure of the i-node open file description 31 32
UNIX File System (4) Network File System (1)
• A BSD directory with three files • The same directory after the file voluminous has • Examples of remote mounted file systems been removed • Directories are shown as squares, files as circles 33 34
Network File System (2) Security in UNIX
The NFS layer structure.
The NFS layer structure Some examples of file protection modes
35 36
6