Next: Mach Design
Up: 4560
Previous: XINU: System Design
  Contents
- no real design before implementation
- first development in 1969 at Bell Labs by Thompson and Ritchie
- Ritchie had worked on MULTICS
- UNIX is a pun on MULTICS
- file system and shell are similar
- implemented in C
- designed by programmers for programmers
- designed to be a time-sharing system
- not much layering (see earlier slide)
- shell programs combine ordinary programs
- pipes for redirection of input/output:
% myprog <indata >outdata
UNIX: Processes [283]
- process is a program in execution
- new process created by fork
- parent can create a child
- child runs the same program as parent
- typically, child will execve a new program
- parent waits for a child's exit
- if a parent exits, then the child is a zombie
- fork allows a pipe between parent and child (see IPC)
- read from empty pipe or write to full pipe: block
- signal handles exceptional conditions (keyboard interrupt)
- process can ignore a signal or have a signal handler routine
- signals can be used to start and stop subprocesses on demand
UNIX: Process Control Block [284]
- called process structure
- process ID, priority, etc.
- array of PCBs defined at system linking time
- ready queue is doubly-linked list through the PCBs
- pointers to parent, youngest living child, other relatives
- normal execution is in user mode
- system calls switch to system mode
- system mode uses kernel stack for that process
UNIX: Scheduling [285]
- designed to benefit interactive processes
- small CPU time slices using a priority algorithm
- larger numbers indicate lower priority
- processes doing disk I/O are less than ``pzero''
- ordinary user processes have positive priorities
- less likely to run than any system process
- user processes can set precedence over one another using nice
- high CPU usage IMPLIES lower priority (more positive)
- process aging prevents starvation
- time-slice every 0.1 sec and recompute priorities every 1 second
- round-robin uses timeout which tells clock to interrupt
- reschedule and then set another timeout
- priority recomputation also uses timeout
UNIX: Events [286]
- relinquish CPU because of I/O or time slice expired
- or sleep waiting for some event
- argument is address of kernel data structure for that specific event
- system calls wakeup on all sleeping processes for that event
- wait for disk I/O to complete (sleep on address of buffer header)
- race condition:
- process decides to sleep (based on, say, flag)
- event occurs
- process calls sleep (but event will never occur)
- raise hardware processor priority for this critical section
- no interrupts and process can run until sleeping
UNIX: Memory Management [287]
- early system just swapped out processes if not enough memory
- PID0=scheduler process (swapper) wakes up every 4 secs
- swap out a process if:
- idle
- in main memory a long time
- large
- old
- swap in a process if:
- swapped out a long time
- small
- some UNIX systems still do this
- Berkeley UNIX uses demand paging and secondarily swapping
UNIX: Demand Paging [288]
- virtual memory
- swapping kept to minimum because more jobs in memory
- only parts of each process in memory
- list of free frames
- modification of second chance (clock) algorithm
- memory is swept linearly and repeatedly by software clock hand
- if frame is already free or in use (say for I/O), skip
- otherwise, go to page-table entry for frame
- if invalid, put frame on free list
- otherwise, mark as invalid but reclaimable
- clock hand implemented by pagedaemon
- runs only if free frames falls below threshold
- if hardware supports ref bit, then use it
- one pass of the clock turns bits off
- second pass checks bit and puts onto free list
UNIX: File System [289]
- file is a sequence of bytes
- files organized by directories
- file data linked by inodes (see earlier slide)
- system calls use a file descriptor as an argument
- kernel indexes into table of open files for current process
- each entry points to a file structure
- each file structure points to an inode
UNIX: I/O System [290]
- disk files and I/O devices treated as similarly as possible
- general device driver code
- specific device driver code for each device
- block devices
- disks and tapes
- array of entry points for drivers
- use a block buffer cache for block I/O
- or use a queue of pending transfers for raw device interfaces
- character devices
- terminals, line printers, etc.
- array of entry points for drivers
- C-lists are small blocks of characters
- write enqueues onto the list for the device
- interrupts cause dequeueing
- input is also interrupt driven
UNIX: IPC [291]
- not one of the strong points of UNIX
- pipe, shared files, messages, shared memory
- sockets
- stream: reliable and sequenced stream
- datagram: unreliable and unsequenced messages
- socket creates a socket and returns descriptor
- descriptor indexes into array of open ``files''
- bind assigns a name to a socket
- client-server model
- server creates socket and binds to well-known address
- client uses connect on well-known address
- server listens to say that it is ready for connections
- server accepts individual connection
- server usually forks a process to talk with client
- server goes back to listening
- server subprocess and client do read and write
Next: Mach Design
Up: 4560
Previous: XINU: System Design
  Contents
Ted Billard
2001-11-17