Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems CSCI 411 Introduction Content from Operating Systems in Depth Thomas w. Doeppner ©2011 Operating Systems Principles & Practices by Anderson.

Similar presentations


Presentation on theme: "Operating Systems CSCI 411 Introduction Content from Operating Systems in Depth Thomas w. Doeppner ©2011 Operating Systems Principles & Practices by Anderson."— Presentation transcript:

1 Operating Systems CSCI 411 Introduction Content from Operating Systems in Depth Thomas w. Doeppner ©2011 Operating Systems Principles & Practices by Anderson and Dahlin 2014 M. Doman

2 Main Points (for today) Operating system definition – Software to manage a computer’s resources for its users and applications OS challenges – Reliability, security, responsiveness, portability, … OS history

3 In the Beginning … There was hardware – processor – storage – card reader – tape drive – drum And not much else – no operating system – no libraries – no compilers

4 OS History

5 IBM 650 OS: none get photo from: 03.ibm.com/ibm/history/exhibits/650/650_ph10.html]

6 Programming Without an OS Assemble all software into a deck of punched cards Get 15-minute computer slot 1)pay $75 ($611 in 2010 dollars) 2)mount tapes containing data 3)read cards into computer 4)run program – it probably crashes 5)output (possibly a dump) goes to printer Steps 1, 2, 3, and 5 take 10 minutes – leaving 5 minutes for step 4!

7 Enter the OS … Group jobs into batches Setup done for all collectively Software doing this called Input/Output System – the first operating system

8 Computer Performance Over Time

9 Early Operating Systems: Computers Very Expensive One application at a time – Had complete control of hardware – OS was runtime library – Users would stand in line to use the computer Batch systems – Keep CPU busy by having a queue of jobs – OS would load next job while current one runs – Users would submit jobs, and wait, and wait, and

10 Time-Sharing Operating Systems: Computers and People Expensive Multiple users on computer at same time – Multiprogramming: run multiple programs at same time – Interactive performance: try to complete everyone’s tasks quickly – As computers became cheaper, more important to optimize for user time, not computer time

11 Today’s Operating Systems: Computers Cheap Smartphones Embedded systems Web servers Laptops Tablets Virtual machines …

12 Tomorrow’s Operating Systems Giant-scale data centers Increasing numbers of processors per computer Increasing numbers of computers per user Very large scale storage

13 Bonus Thought Question How should an operating system allocate processing time between competing uses? – Give the CPU to the first to arrive? – To the one that needs the least resources to complete? To the one that needs the most resources? – What if you need to allocate memory? – Disk?

14 What is an operating system? Software to manage a computer’s resources for its users and applications

15 Operating System Roles Referee: – Resource allocation among users, applications – Isolation of different users, applications from each other – Communication between users, applications Illusionist – Each application appears to have the entire machine to itself – Infinite number of processors, (near) infinite amount of memory, reliable storage, reliable network transport Glue – Libraries, user interface widgets, …

16 Thought Question What do you need from hardware to be able to: – Isolate different applications from each other? – Isolate different users from accessing each others files?

17 Example: web service How does the server manage many simultaneous client requests? How do we keep the client safe from spyware embedded in scripts on a web site? How do we keep updates to the web site consistent?

18 OS Challenges Reliability – Does the system do what it was designed to do? – Availability What portion of the time is the system working? Mean Time To Failure (MTTF), Mean Time to Repair Security – Can the system be compromised by an attacker? – Privacy Data is accessible only to authorized users Both require very careful design and code

19 OS Challenges Portability – For programs: Application programming interface (API) Abstract machine interface – For the operating system Hardware abstraction layer Hardware-specific OS kernel routines

20 OS Challenges Performance – Latency/response time How long does an operation take to complete? – Throughput How many operations can be done per unit of time? – Overhead How much extra work is done by the OS? – Fairness How equal is the performance received by different users? – Predictability How consistent is the performance over time?

21 What are Operating Systems? Possible definitions: – the code that {Microsoft, Apple, Linus, Google} provides – the code that you didn’t write – the code that runs in privileged mode – the code that makes things work – the code that makes things crash – etc.

22 Operating Systems Abstraction – providing an “appropriate” interface for applications Concerns – performance time and space – sharing and resource management – failure tolerance – security – marketability

23 Abstractions Hardware – disks – memory – processors – network – monitor – keyboard – mouse Operating system – files – programs – threads of control – communication – windows, graphics – input – locator

24 Files Memory Disk

25 Issues Naming Allocating space on disk (permanent storage) – organized for fast access – minimize waste Shuffling data between disk and memory (high- speed temporary storage) Coping with crashes

26 File-Descriptor Table n–1 File-descriptor table File descriptor User address space Kernel address space ref count access mode file location inode pointer

27 Programs Data Code Memory Processor Disk Processor

28 Memory Sharing (1) Memory Program 1 Program 2 Program 3 Operating System

29 Memory Sharing (2) Program 1 Program 2 Program 3 Memory

30 Virtual Memory Program 1 Program 2 Program 3 Memory Disk

31 Hardware Memory Network Processor Disk

32 Concurrency Processor Virtual Processor

33 Parallelism Processor Virtual Processor Processor

34 Textbook Lazowska, Spring 2012: “The text is quite sophisticated. You won't get it all on the first pass. The right approach is to [read each chapter before class and] re-read each chapter once we've covered the corresponding material… more of it will make sense then. Don't save this re-reading until right before the mid-term or final – keep up.”

35 1960s OS Issues Multiprogramming Time sharing Software complexity Security

36 2010s OS Issues Multiprogramming – not just one computer, but server farms Time sharing – voice, video, sound, etc. Software complexity – a bigger problem than could be imagined in the ’60s Security – ditto

37 1950s Commercial data processing Scientific computing

38 1960s Commercial data processing Scientific computing Time sharing Laboratory computing

39 Atlas Computer [get drawing from: computing.org.uk/acl/technology/atlas/p002.htm]

40 The IBM Mainframe OS: OS/360 [get photo from: 03.ibm.com/ibm/history/exhibits/mainframe/mainframe_intro2.h tml]

41 IBM 7094 OS: CTSS (among others) [get photo from: 03.ibm.com/ibm/history/exhibits/mainframe/mainframe_PP7094.html]

42 Multics [get photo from:

43 DEC PDP-8 OS: many: ranging from primitive to interesting (a multi- user time-sharing system; a virtual- machine system)

44 Unix [get photo from:

45 History of Concurrency Multiprogramming – 1961, 1962: Atlas, B5000 – 1965: OS/360 MFT, MVT Timesharing – 1961: CTSS (developed by MIT for IBM 7094); BBN time-sharing system for DEC PDP-1 – mid 60s Dartmouth Timesharing System (DTSS) TOPS-10 (DEC) – late 60s Multics (MIT, GE, Bell Labs) Unix (Bell Labs)

46 Apple’s Multitasking Announcement With Preemptive Multitasking, Everything Happens at Once In today’s fast-paced world, you rarely get to do one thing at a time. Even in the middle of transforming, say, a Photoshop file, you may need to find a crucial piece of information on the web while you compose an urgent reply to a customer. What you need is a computer that can handle several different tasks at once, giving priority to your primary application, but still crunching away at other jobs in the background. … Darwin makes this possible by incorporating a powerful concept called preemptive multitasking. … — Apple website, September 2000

47 History of Virtual Memory 1961: Atlas computer, University of Manchester, UK 1962: Burroughs B : IBM OS/ : 3 BSD Unix, UC Berkeley 1993: Microsoft Windows NT : Apple Macintosh OS X

48 Apple’s VM Announcement… Welcome to the Brave New World of Crash-Resistant Computing Let’s start with the notion of protected memory, and why it’s so important. … One of the ways an operating system ensures reliability is by protecting applications through a mechanism called protected memory (essentially walling off applications from each other). … Along with the protected memory mechanism, Darwin provides a super-efficient virtual memory manager to handle that protected memory space. So you no longer have to worry about how much memory an application like Photoshop needs to open large files. … — Apple website, September 2000

49 1970s Commercial data processing Scientific computing Time sharing Laboratory computing Personal computing Hobbyist computing

50 IBM’s Dominance Continues OS: OS/370 [get photo from: 03.ibm.com/ibm/history/exhibits/mainframe/mainframe_242 3PH3168.html]

51 Scientific Computing OS: COS: single job at a time

52 Xerox Alto OS: single-user, single- computation [get photo from:

53 MITS ALTAIR 8800 OS: none [get photo from: computer.com/altair8800.shtml]

54 CP/M Control Program for Microcomputers – 1974 – first hobbyist OS – supported Intel 8080 and other systems clear separation of architecture-dependent code – no multiprogramming – no protection

55 Apple II OS: none later: similar functionality as CP/M (not much) [get photo from:

56 Microsoft Enters the OS Business: Late 1970s It’s called … – Xenix a version of Unix – predominant version of Unix in the 1980s – used by MS internally into the 1990s

57 VAX-11/780 OS: VMS Unix Both: time sharing virtual memory access protection concurrency

58 1980s Commercial data processing Scientific computing Time sharing Laboratory computing Personal Professional computing Hobbyist Personal computing

59 Two OSes Take Off UnixMS-DOS

60 IBM PC OS: PC-DOS (aka MS-DOS) (remarkably like CP/M) [get photo from: 03.ibm.com/ibm/history/history/history_intro.html]

61 The Computer Workstation OS: Aegis supported: virtual memory distributed file system access protection concurrency

62 1990s Commercial data processing Scientific computing High-end personal computing Low-end personal computing

63 Toy Operating Systems 1987: Andrew Tanenbaum of Vrije Universiteit, Amsterdam, publishes Operating Systems: Design and Implementation – included is source code for a complete, though toy, operating system: Minix, sort of based on Unix 1991: Linus Torvalds buys an Intel 386 PC – MS-DOS doesn’t support all its features (e.g., memory protection, multi-tasking) – “soups up” Minix to support all this January 1992: Torvalds releases Linux 0.12 January 1992: Tanenbaum declares Linux obsolete

64 Late 80s/Early 90s 1988: Most major Unix vendors get together and form OSF to produce a common Unix: OSF/1, based on IBM’s AIX 1989: Microsoft begins work on NT 1990: OSF abandons AIX, restarts with Mach 1991: OSF releases OSF/1 1992: Sun releases Solaris 2 – many SunOS (Solaris 1) programs are broken 1993: All major players but DEC have abandoned OSF/1 1993: Microsoft releases Windows NT : Linux 1.0 released

65 Late 90s IBM has three different versions of Unix, all called “AIX” 1996: DEC renames its OSF/1 “Digital Unix” 1996: Microsoft releases Windows NT : Linux 2.0 released 1998: DEC is purchased by Compaq; “Digital Unix” is renamed “Tru64 Unix” 1999: Sun’s follow-on to Solaris 2.6 is called Solaris 7

66 2000s Commercial data processing Scientific computing Gadgets Personal computing

67 The ’00s Part : Microsoft releases Windows 2000 and Windows Me 2000: Linux 2.2 is released 2000: IBM “commits” to Linux (on servers) ~2000: Apple releases OS X, based on Unix (in particular, OSF/1) 2001: Linux 2.4 is released 2001: Microsoft releases Windows XP 2002: Compaq is purchased by HP 2003: SCO claims their code is in Linux, sues IBM; IBM countersues – August 10, 2007: judge rules that SCO is not the rightful owner of the Unix copyright, Novell is – Novell says there is no Unix in Linux – September 2007: SCO files for Chapter 11 bankruptcy protection

68 The ’00s Part : Linux 2.6 is released 2005: IBM sells PC business to Lenovo July 2005: Microsoft announces Windows Vista January 2007: Microsoft releases Windows Vista later in 2007: Microsoft starts hinting at Windows 7 April 2009: Oracle announces purchase of Sun Microsystems July 2009: Google announces Chrome OS October 2009: Microsoft releases Windows 7

69 History of C Early 1960s: CPL (Combined Programming Language) – developed at Cambridge University and University of London 1966: BCPL (Basic CPL): simplified CPL – intended for systems programming 1969: B: simplified BCPL (stripped down so its compiler would run on minicomputer) – used to implement earliest Unix Early 1970s: C: expanded from B – motivation: they wanted to play “Space Travel” on minicomputer – used to implement all subsequent Unix OSes

70 A Simple OS

71 Outline Unix overview – processes – file abstraction – directories – file representation – file-oriented system calls

72 A Program const int nprimes = 100; int prime[nprimes]; int main() { int i; int current = 2; prime[0] = current; for (i=1; i

73 Processes Fundamental abstraction of program execution – memory – processor(s) each processor abstraction is a thread – “execution context”

74 The Unix Address Space text data bss dynamic stack

75 Modified Program const int nprimes = 100; int *prime; int main(int argc, char *argv[]) { int i; int current = 2; nprimes = atoi(argv[1]); prime = (int *)malloc(nprimes*sizeof(int)) prime[0] = current; for (i=1; i

76 Creating a Process: Before fork( ) parent process

77 Creating a Process: After fork( ) // returns p parent process fork( ) // returns 0 child process (pid = p)

78 Process Control Blocks PID Terminated children Link Return code Process Control Block PID Terminated children Link Return code PID Terminated children Link Return code

79 Fork and Wait short pid; if ((pid = fork()) == 0) { /* some code is here for the child to execute */ exit(n); } else { int ReturnCode; while(pid != wait(&ReturnCode)) ; /* the child has terminated with ReturnCode as its return code */ }

80 Exec int pid; if ((pid = fork()) == 0) { /* we’ll soon discuss what might take place before exec is called */ execl("/home/twd/bin/primes", "primes", "300", 0); exit(1); } /* parent continues here */ while(pid != wait(0))/* ignore the return code */ ;

81 Loading a New Image exec(prog, args) Before prog’s text prog’s data prog’s bss args After

82 System Calls Sole interface between user and kernel Implemented as library routines that execute trap instructions to enter kernel Errors indicated by returns of –1; error code is in errno if (write(fd, buffer, bufsize) == –1) { // error! printf("error %d\n", errno); // see perror }

83 System Calls write(fd, buf, len) kernel text other stuff kernel stack trap into kernel User portion of address space Kernel portion of address space

84 other stuff kernel stack other stuff kernel stack other stuff kernel stack other stuff kernel stack Multiple Processes kernel text

85 The File Abstraction A file is a simple array of bytes Files are made larger by writing beyond their current end Files are named by paths in a naming tree System calls on files are synchronous

86 Standard File Descriptors main( ) { char buf[BUFSIZE]; int n; const char* note = "Write failed\n"; while ((n = read(0, buf, sizeof(buf))) > 0) if (write(1, buf, n) != n) { (void)write(2, note, strlen(note)); exit(EXIT_FAILURE); } return(EXIT_SUCCESS); }

87 Back to Primes … int nprimes; int *prime; int main(int argc, char *argv[]) { … for (i=1; i

88 Human-Readable Output int nprimes; int *prime; int main(int argc, char *argv[]) { … for (i=1; i

89 Running It if (fork() == 0) { /* set up file descriptor 1 in the child process */ close(1); if (open("/home/twd/Output", O_WRONLY) == -1) { perror("/home/twd/Output"); exit(1); } execl("/home/twd/bin/primes", "primes", "300", 0); exit(1); } /* parent continues here */ while(pid != wait(0))/* ignore the return code */ ;

90 File-Descriptor Table n–1 File-descriptor table File descriptor User address space Kernel address space ref count access mode file location inode pointer

91 Allocation of File Descriptors Whenever a process requests a new file descriptor, the lowest numbered file descriptor not already associated with an open file is selected; thus #include close(0); fd = open("file", O_RDONLY); – will always associate file with file descriptor 0 (assuming that the open succeeds)

92 Redirecting Output … Twice if (fork() == 0) { /* set up file descriptors 1 and 2 in the child process */ close(1); close(2); if (open("/home/twd/Output", O_WRONLY) == -1) { exit(1); } if (open("/home/twd/Output", O_WRONLY) == -1) { exit(1); } execl("/home/twd/bin/program", "program", 0); exit(1); } /* parent continues here */

93 Redirected Output File-descriptor table File descriptor 1 User address space Kernel address space File descriptor 2 1 WRONLY 0 inode pointer 1 WRONLY 0 inode pointer

94 Redirected Output After Write File-descriptor table File descriptor 1 User address space Kernel address space File descriptor 2 1 WRONLY 100 inode pointer 1 WRONLY 0 inode pointer

95 Sharing Context Information if (fork() == 0) { /* set up file descriptors 1 and 2 in the child process */ close(1); close(2); if (open("/home/twd/Output", O_WRONLY) == -1) { exit(1); } dup(1); /* set up file descriptor 2 as a duplicate of 1 */ execl("/home/twd/bin/program", "program", 0); exit(1); } /* parent continues here */

96 Redirected Output After Dup File-descriptor table File descriptor 1 User address space Kernel address space File descriptor 2 2 WRONLY 100 inode pointer

97 Fork and File Descriptors int logfile = open("log", O_WRONLY); if (fork() == 0) { /* child process computes something, then does: */ write(logfile, LogEntry, strlen(LogEntry)); … exit(0); } /* parent process computes something, then does: */ write(logfile, LogEntry, strlen(LogEntry)); …

98 File Descriptors After Fork logfile Parent’s address space Kernel address space 2 WRONLY 0 inode pointer logfile Child’s address space

99 Naming (almost) everything has a path name – files – directories – devices (known as special files) keyboards displays disks etc.

100 Uniformity int file = open("/home/twd/data", O_RDWR); // opening a normal file int device = open("/dev/tty", O_RDWR); // opening a device (one’s terminal // or window) int bytes = read(file, buffer, sizeof(buffer)); write(device, buffer, bytes);

101 Directories unixetchomeprodev twd passwd motdunix...slide1slide2

102 Directory Representation Component NameInode Number unix117 etc4 home18 pro36 dev93 directory entry.1..1

103 Hard Links unixetchomeprodev twd imagemotdunix...slide1slide2 % ln /unix /etc/image # link system call

104 Directory Representation unix117 etc4 home18 pro36 dev image117 motd

105 Soft Links unixetchomeprodev twd imagetwd unix... slide1slide2 % ln –s /unix /home/twd/mylink % ln –s /home/twd /etc/twd # symlink system call mylink /unix /home/twd

106 Working Directory Maintained in kernel for each process – paths not starting from “/” start with the working directory – changed by use of the chdir system call – displayed (via shell) using “pwd” how is this done?

107 Open #include int open(const char *path, int options [, mode_t mode]) – options O_RDONLYopen for reading only O_WRONLY open for writing only O_RDWRopen for reading and writing O_APPENDset the file offset to end of file prior to each write O_CREATif the file does not exist, then create it, setting its mode to mode adjusted by umask O_EXCLif O_EXCL and O_CREAT are set, then open fails if the file exists O_TRUNCdelete any previous contents of the file O_NONBLOCKdon’t wait if I/O can’t be done immediately

108 File Access Permissions Who’s allowed to do what? – who user (owner) group others (rest of the world) – what read write execute

109 Permissions Example % ls -lR.: total 2 drwxr-x--x 2 tom adm 1024 Dec 17 13:34 A drwxr tom adm 1024 Dec 17 13:34 B./A: total 1 -rw-rw-rw- 1 tom adm 593 Dec 17 13:34 x./B: total 2 -r--rw-rw- 1 tom adm 446 Dec 17 13:34 x -rw----rw- 1 trina adm 446 Dec 17 13:45 y

110 Setting File Permissions #include int chmod(const char *path, mode_t mode) – sets the file permissions of the given file to those specified in mode – only the owner of a file and the superuser may change its permissions – nine combinable possibilities for mode (read/write/execute for user, group, and others) S_IRUSR (0400), S_IWUSR (0200), S_IXUSR (0100) S_IRGRP (040), S_IWGRP (020), S_IXGRP (010) S_IROTH (04), S_IWOTH (02), S_IXOTH (01)

111 Creating a File Use either open or creat – open (const char *pathname, int flags, mode_t mode) flags must include O_CREAT – creat(const char *pathname, mode_t mode) open is preferred The mode parameter helps specify the permissions of the newly created file – permissions = mode & ~umask

112 Umask Standard programs create files with “maximum needed permissions” as mode – compilers: 0777 – editors: 0666 Per-process parameter, umask, used to turn off undesired permission bits – e.g., turn off all permissions for others, write permission for group: set umask to 027 compilers: permissions = 0777 & ~(027) = 0750 editors: permissions = 0666 & ~(027) = 0640 – set with umask system call or (usually) shell command

113 What Else? Beyond Sixth-Edition Unix (1975) – multiple threads per process how is the process model affected? – virtual memory fork? – interactive, multimedia user interface scheduling? – networking – security


Download ppt "Operating Systems CSCI 411 Introduction Content from Operating Systems in Depth Thomas w. Doeppner ©2011 Operating Systems Principles & Practices by Anderson."

Similar presentations


Ads by Google