1 / 35

UNIX

UNIX. 1 History of UNIX 2 Overview of UNIX 3 Processes in UNIX 4 Memory management in UNIX 5 The UNIX file system 6 Input/output in UNIX. History of UNIX. MULTICS and UNICS (Thompson) PDP-11 UNIX (B & C, Richie & Tompson) Portable UNIX Berkeley UNIX Standard UNIX

veradis-ace
Download Presentation

UNIX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNIX 1 History of UNIX 2 Overview of UNIX 3 Processes in UNIX 4 Memory management in UNIX 5 The UNIX file system 6 Input/output in UNIX

  2. History of UNIX • MULTICS and UNICS (Thompson) • PDP-11 UNIX (B & C, Richie & Tompson) • Portable UNIX • Berkeley UNIX • Standard UNIX • Linux (Linus Torvald)

  3. UNIX Goals • An interactive system designed to handle multiple pro-cesses and multiple (sophisticated) users at the same time • Group of experienced users != personal computer model • Experienced users want: • simplicity, elegancy, consistency • power and flexibility • avoid useless redundancy

  4. Interfaces to UNIX UserInterface The layers of a UNIX system.

  5. UNIX Shell (Φλοιός) • Shell: a command line interface != X Windows • Faster to use, more powerful, easily extensible • When the shell starts up: initializes it self, types a prompt character. User: types a command line. Shell: extract first word -> program to execute. Shell is just another program • Commands may take arguments, e.g. cp a1.txt b1.txt • Other aspects: flags, wildcards e.g. –2 , */? • Standard input, output, error. Redirection ( <, >). • e.g. sort < in > tmp; head –30 < temp; rm temp • Output of a program is input to another. Pipes (|) • e.g. sort < in | head –30 • Multiple commands: e.g. sort < in > tmp &. Shell scripts.

  6. UNIX Utility Programs A few of the more common UNIX utility programs required by POSIX

  7. Processes in UNIX • Processes are created using the fork system call • Parent and child processes have their own, private memory images. Open files are shared between the two processes • How do the processes know which one should run the parent code and which one should run the child code?

  8. POSIX • Processes communicate with each other: • using a form of message passing (pipes) and with signals The signals required by POSIX.

  9. System Calls for Process Management s is an error code pid is a process ID residual is the remaining time from the previous alarm

  10. POSIX Shell A highly simplified shell

  11. UNIX Processes: Implementation • Two data structures: process table and user structure • Process table (keeps information for all processes): • Scheduling parameters (process priority, amount of CPU time consumed recently, sleeping time recently) • Memory image (pointers to text, data and stack segments) • Signals (masks showing treatment of signals) • Miscellaneous (process state, event being waited for, PID, etc.) • User structure (only if process in memory and runnable) • Machine registers • System call state • File descriptor table (used to locate the i-nodes) • Accounting (CPU used so far)

  12. The ls Command Steps in executing the command ls type to the shell

  13. UNIX Scheduler • Designed to provide good response to interactive processes • Two-level algorithm • Low-level: picks the process to run next from the runnable ones • High level: moves processes between memory and disk • Low level algorithm: • Uses multiple queues, each with a range of priorities values • Processes in user mode have positive values, kernel mode negative • A process run for a quantum (usually 100msec) or until it blocks and then it is put on the end of the queue • Every second: priority = CPU_usage + nice + base

  14. UNIX Scheduler The UNIX scheduler is based on a multilevel queue structure

  15. Booting UNIX The boot program located in the MBR runs first and loads the O.S. The sequences of processes used to boot some systems cp

  16. Handling Memory Process A Process B • Process A's virtual address space (text,data and stack) • Physical memory • Process B's virtual address space (text, data and stack)

  17. System Calls for Memory Management • s is an error code • b and addr are memory addresses • len is a length • prot controls protection • flags are miscellaneous bits • fd is a file descriptor • offset is a file offset

  18. Implementation of Paging in UNIX • Earlier UNIX systems used swapping (low-level scheduling) • On-demand • No prepaging • Page daemon • OS, core map and page frames The core map has an entry for each page

  19. Page Replacement in UNIX • When a page fault occurs and the there is no available page, process is suspended until page daemon has freed some. • Page replacement algorithm is executed by page daemon; every 250 msec it checks if free pages >= lotsfree parameter • If not, it transfers pages to disk so free pages >= lotsfree • Modified version of the clock algorithm; global replacement • Two-hand clock algorithm: the page daemon maintains two pointers into the core map. When it runs, it first clears the usage bit at the front end and then checks the usage bit at the back end, after which it advances both hands.

  20. The UNIX File System Some important directories found in most UNIX systems

  21. The UNIX File System • Before linking. • After linking. (a) Before linking. (b) After linking

  22. The UNIX File System • Separate file systems • After mounting (a) (b) (a) Before mounting. (b) After mounting

  23. Locking Files (a) File with one lock (b) Addition of a second lock (c) A third lock Exclusive and Shared Locks: similar to read and write locks

  24. System Calls for File Management • s is an error code • fd is a file descriptor • position is a file offset

  25. The lstat System Call Fields returned by the lstat system call.

  26. System Calls for Directory Management • s is an error code • dir identifies a directory stream • dirent is a directory entry

  27. UNIX File System Disk layout in classical UNIX systems

  28. UNIX File System Directory entry fields. Structure of the i-node

  29. UNIX File System • Example: n = read (fd, buffer, nbytes) • When kernel gets control, all it has is just 3 parameters. It has to locate the i-node. Also store the file position. • One of the internal tables: file descriptor array • One possibility: have a pointer to the i-node at the file descriptor and keep file position in the i-node. FAILS (?) • Another possibility: keep file position in the file descriptor array. What happens if a child process modifies the file? • Introduce a new table, the open file description between the file descriptor table and the i-node table.

  30. UNIX File System The relation between the file descriptor table, the open file description

  31. UNIX I/O System • All I/O devices are made to look like files and are accessed with the same read/write system calls. • UNIX integrates I/O devices to the file system as special files. E.g. /dev/hd1 (hard disk), /dev/lp1 (printer), /dev/net. • Programs can read/write special files the same way with regular files. E.g. cp account.txt /dev/lp1 • Special files: • block: sequence of numbered blocks (e.g. disks) • character: input or output character streams (e.g. keyboard, printer)

  32. Networking • Sockets are analogous to mailboxes or wall sockets and are used for networking • Sockets are created (returns a file descriptor) and destroyed dynamically • Each socket supports: • reliable connection-oriented byte stream (equivalent of a pipe between 2 processes) • reliable connection-oriented packet stream (preserves packet boundaries) • unreliable packet transmission (access to the raw network – no guarantees) • Before a socket can be used, it must have an address

  33. Terminal Management The main POSIX calls for managing the terminal

  34. UNIX I/O Some of the fields of a typical cdevsw table

  35. UNIX I/O The UNIX I/O system in BSD

More Related