1 / 19

Intro to Unix for Smart People Part I

Intro to Unix for Smart People Part I. Joe Morrison, Lab49. GE 645. (Artist’s rendition). GE 645 Specs. Dual-core .000435 GHz 3 Mb RAM 16 Mb swapping drum 136 Mb HD. Multics achievements. Modular design Memory mapped files Dynamic linking Hot swappable everything

meagan
Download Presentation

Intro to Unix for Smart People Part I

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. Intro to Unix for Smart People Part I Joe Morrison, Lab49

  2. GE 645 (Artist’s rendition)

  3. GE 645 Specs • Dual-core .000435 GHz • 3 Mb RAM • 16 Mb swapping drum • 136 Mb HD

  4. Multics achievements • Modular design • Memory mapped files • Dynamic linking • Hot swappable everything • Ring oriented security • First OS to have a hierarchical file system • Symlinks • Per-process stacks

  5. Verdict • Only supported 35 users • Performance deemed inadequate • Verdict: Failure • Bell Labs: “We’re out of here.”

  6. Take 2: Unics • Bell Labs pulled out of Multics in 1969 • Started work on a simpler alternative • Unics = Uniplexed Information and Computing System • Also a pun on Eunuchs • Later name simplified to Unix

  7. Unix family tree (simplified) 1970 AT&T Bell Labs UC Berkeley 1 BSD Version 7 1980 Microsoft 4.2 BSD Unix System III Xenix SUN Microsystems Unix System V SUN OS Licenses 4.3 BSD 1990 Linux Novell Solaris SCO Red Hat Caldera 2000 SCO Group Lawsuits

  8. Strange and wonderful: fork() int pid = fork (); if (pid == 0){ /* I am the child process */}else { /* I am the parent process and pid is my new child*/ }

  9. exec () • exec family of system calls • execl, execv, execle, execve, execlp, execvp • Load executable file and replace myself (while keeping same process identity and resources) … /* goodbye, cruel world */ exec (“/bin/foo”); LOAD /bin/foo /* not reached */ /* process continues with code loaded from /bin/foo */ …

  10. Launching a program pid_t pid; if ((pid = fork ()) == 0) { exec (…); /* not reached */ } /* child has been launched – parent can wait if desired */ int status; while (wait (&status) != pid) ;

  11. Orphans and zombies • Zombies (defunct processes) • All processes have entries in a process table • When child terminates and parent calls wait(), entry is removed • If child terminates, but parent does not wait()– zombie (dead but not reaped) • Orphans • If parent dies before child, child becomes an orphan and is adopted by “init” • If child exits and parent dies without calling wait(), child is an orphan zombie • No problem, “init” periodically checks all its adoptees and reaps them when they terminate

  12. Unix system startup /etc/inittab getty fork/exec (respawn) exec login init (pid = 1) exec fork/exec (respawn) sh getty exec login Start other required processes exec sh

  13. Simple structure is very adaptable • Shell is just a program, not a deep component of the OS • Anybody can write one! • Easy to provide computing services to anything that can send/receive chars • For example telnetd • Listen on a port • When an incoming request is received, fork a handler process and exec login

  14. A small but working shell main () { while (1) { printf ("49: "); char line [1024]; if ((fgets (line, sizeof line, stdin) == 0) || (strncmp (line, "quit", 4) == 0)) { exit (0); } char *tokens [256]; tokens [0] = strtok (line, " \n"); int i = 1; while (tokens [i++] = strtok (0, " \n")) { if (i == 255) break; } tokens [i] = 0; for (i=0; i<2; i++) { pid_t pid; int status; if ((pid = fork ()) == 0) { execvp (tokens[0], tokens); perror ("error"); exit (1); } else { while (wait (&status) != pid) ; } } } } 49: ls foo.txt bar.txt baz.txt foo.txt bar.txt baz.txt 49:

  15. A history of shells • Bourne shell (sh) – the classic • Slightly unwieldy for interactive use • ash - lightweight version of sh • csh – better interactivity, crappy for programming • tcsh – fewer bugs, more features • ksh – Korn shell (great but not free) • bash – Bourne again shell (learn this one) • rc – a shell for Plan9 - simple and clean • zsh – another feature-laden shell • es – an enhanced version of rc

  16. Bash shell examples # example 1 foo > bar 2>&1 # example 2 foo 2>&1 > /tmp/out | wc # example 3 mkfifo /tmp/fifo foo > /tmp/fifo 2>&1 & ... cat /tmp/fifo # example 4 for i in `grep -l foo *` do cp $i $i.saved done # example 5 find /home/jdm -type f -iname '*foo*' | xargs grep bar # or even better (handles filenames with spaces) find /home/jdm -type f -iname '*foo*‘ -print0 | xargs -0 grep bar

  17. Closing thoughts • In general Unix desktops are primitive compared to other popular operating systems • (NeXT and Mac being notable exceptions) • But it’s not just about features, ease of use, and stability • (This better be good) • It’s also about internal interfaces • Make OS reusable in more contexts • Create a breeding ground for improvements • For example • Accessibility (rewrite the window manager) • Embedded systems (replace /etc/inittab)

  18. Unix versus Windows • Windows: Best platform for creating end-user applications • Unix: Best set of building blocks for general purpose, secure, multi-user, multi-process computing

  19. Final closing thoughts (really) • Windows • Intelligent design • Unix • Mutation and natural selection

More Related