CPS221 Lecture: Operating System Functions

Similar documents
CPS221 Lecture: Operating System Functions

CPS221 Lecture: Operating System Protection

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

TDDI04, K. Arvidsson, IDA, Linköpings universitet Operating System Structures. Operating System Structures Overview. Operating System Services

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

Operating System Services

CPS221 Lecture: Threads

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

ELEC 377 Operating Systems. Week 1 Class 2

Chapter 2: Operating-System Structures

Operating Systems Overview. Chapter 2

What is UNIX? A Little Bit about UNIX and User Interfaces. Adapted from Practical Unix and Programming Hunter College

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Operating Systems. Copyleft 2005, Binnur Kurt

Multiprogramming. Evolution of OS. Today. Comp 104: Operating Systems Concepts 28/01/2013. Processes Management Scheduling & Resource Allocation

Definition: An operating system is the software that manages resources

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

13-2 EE 4770 Lecture Transparency. Formatted 8:18, 13 March 1998 from lsli

Lecture 2 - Fundamental Concepts

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Lecture 2: September 9

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Process Description and Control

CS 390 Chapter 2 Homework Solutions

Chapter 2: Operating-System Structures

Chapter 2 Operating-System Structures

Operating Systems CS3502 Spring 2018

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

Unit 2 : Computer and Operating System Structure

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

CS420: Operating Systems. OS Services & System Calls

Chapter 2: Operating-System Structures

Operating System Structure

Lecture 2 Operating System Structures (chapter 2)

Chapter 2: Operating-System Structures. Operating System Concepts Essentials 8 th Edition

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Chapter 2: Operating-System Structures

Chapter 2: Operating-System

Chap2: Operating-System Structures

AMSC/CMSC 662 Computer Organization and Programming for Scientific Computing Fall 2011 Operating Systems Dianne P. O Leary c 2011

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

Operating System Structure

Chapter 2: Operating-System Structures. Chapter 2: Operating-System Structures. Objectives. Operating System Services

Chapter 4: Threads. Chapter 4: Threads

Chapter 3 Process Description and Control

EECS 3221 Operating System Fundamentals

(Refer Slide Time: 1:26)

EECS 3221 Operating System Fundamentals

CS370 Operating Systems

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

Chapter 2: System Structures

UNIX 2 OPERATING SYSTEM

An Overview of the BLITZ System

Chapter 2: System Structures. Operating System Concepts 9 th Edition

OPERATING SYSTEMS UNIT - 1

Operating System Architecture. CS3026 Operating Systems Lecture 03

Problem Set: Processes

Operating Systems 2010/2011

Chapter 4: Multithreaded Programming

What are some common categories of system calls? What are common ways of structuring an OS? What are the principles behind OS design and

3.1 Introduction. Computers perform operations concurrently

Unix/Linux: History and Philosophy

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Chapter 4: Threads. Operating System Concepts 9 th Edition

Objectives. Chapter 2: Operating-System Structures. 2.1 Operating System Services

Chapter 4: Multithreaded Programming

Reserves time on a paper sign-up sheet. Programmer runs his own program. Relays or vacuum tube hardware. Plug board or punch card input.

OPERATING SYSTEM. Chapter 4: Threads

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

OS structure. Process management. Major OS components. CSE 451: Operating Systems Spring Module 3 Operating System Components and Structure

Introduction to Linux

Chapter 3 Process Description and Control

Process Time. Steven M. Bellovin January 25,

Operating-System Structures

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

Chapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition,

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - VII CPU Scheduling - II. Louisiana State University

Roadmap. Multilevel Queue Scheduling. Multilevel Queue. Example of Multilevel Feedback Queue. Multilevel Feedback Queue. Tevfik Ko!

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Hardware OS & OS- Application interface

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Introduction to PC Operating Systems

Operating Systems. Operating Systems

Distributed Systems Operation System Support

CSE 4/521 Introduction to Operating Systems. Lecture 29 Windows 7 (History, Design Principles, System Components, Programmer Interface) Summer 2018

Introduction to Linux

CSE506: Operating Systems CSE 506: Operating Systems

! Software ( kernel ) that runs at all times. ! OS performs two unrelated functions: Maria Hybinette, UGA. user! 1! Maria Hybinette, UGA. user! n!

Module 1. Introduction:

Chapter 4: Threads. Operating System Concepts 9 th Edition

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Announcement. Exercise #2 will be out today. Due date is next Monday

Overview of Operating Systems

Threads. CS3026 Operating Systems Lecture 06

OS Structure. Hardware protection & privilege levels Control transfer to and from the operating system

CS307: Operating Systems

Transcription:

CPS221 Lecture: Operating System Functions Objectives last revised 6/23/10 1. To overview key hardware concepts 2. To iintroduce the process concept 3. To discuss the various kinds of functionality of the OS I. Introduction A. Operating systems play a central role in the operation of most computer systems. In fact, when one speaks of a computer system, one often refers to the operating system - e.g. a Windows machine or a Linux machine or a Macintosh (Only in the latter case does the name say anything about the hardware, and only because MacOS only runs on machines made by Apple). B. In essence, what the operating system does is to create a layer of abstraction around the basic hardware, such that the user does not see the actual underlying machine, but rather a virtual machine that the operating system provides: User Application Programs Operating System Hardware 1. The user and the application programs do not see the hardware directly, but only through the operating system. 2. One benefit of this abstraction is that it hides differences in machines from the user, so that the user can focus on the general solution to his problem, rather than the intricacies of a particular machine it runs on. This facilitates portability of programs. 3. The UNIX operating system has carried this even further. a) Most operating systems are specific to a particular type of CPU and even manufacturer. (e.g. the 80x86 family for Windows; 80x86 made by Apple for MacOS), 1

b) UNIX and Unix-like systems (including Linux) have been implemented on many different CPU's. Application programs may, of course, need to be recompiled for a particular hardware architecture, since the machine language is different; but the basic UNIX file system and system services is the same in all cases, so that Unix-like programs are highly portable from machine to machine. C. One way to view an operating system is in terms of four basic interfaces: 1. The interface to the underlying hardware (specific to a particular machine). A modern operating system is responsible for managing five general categories of hardware resources: a) The CPU itself b) Primary memory c) Various sorts of IO devices (1) One user at a time devices like a printer, keyboard, or monitor (2) The file system (3) Networking capabilities 2. The interface to application programs (should look the same whereever a given operating system is implemented) 3. The interface to the user (command language, utilities) 4. The interface to system management capabilities. D. Each of these interfaces provides a "view" of the operating system that is important to certain kinds of people. 1. People who build interfaces for new kinds of hardware devices are, of course, most interested in the operating system's hardware interface. 2. Application programmers are primarily interested in the operating system's program interface - though they also use the user interface in their work. 3. Many users are only interested in the user interface. Indeed, many popular books about particular operating systems deal primarily with this aspect. 2

4. More sophisticated users and system managers are also concerned with the administrative interfaces. E. Many operating systems are delivered as three major components: a kernel plus a collection of libraries plus a collection of system programs. 1. The core of the operating system (the operating system proper) provides the first interface, plus some additional functionality we will discuss. 2. The libraries provide the second interface, relying on mechanisms provided by the operating system proper. 3. The system programs provide the latter two, relying on mechanisms provided by the operating system proper and the libraries. 4. Our principle focus in the course will be on the hardware and the application program interface, though we will say a bit about the user and management interfaces. II. The Operating System Proper A. The operating system proper directly controls the hardware. There are a few fundamental hardware concepts that are important to understand at this point. 1. The notion of CPU mode. a) General-purpose CPU s typically operate in one of two modes - kernel and user. (1) This is often specified by a single bit in the CPU s state. (2) When the CPU is in kernel mode (a) Any instruction in its instruction set is legal (b) Any location in its physical memory is accessible (c) Any IO device can be accessed (3) When the CPU is in kernel mode (a) Certain privileged instructions cannot be executed - e.g. the instruction that halts the CPU, or that changes its mode. 3

(b) There are restrictions on what locations in physical memory can be accessed, and on the nature of that access (read only or read and write) (c) IO devices generally cannot be accessed. (d) If code executing in user mode attempts to perform some operation it is not allowed to perform, a trap to operating system code occurs. b) This distinction provides the basis for protecting the operating system from user code, and for preventing different users from interfering with each other. (1) User code cannot execute an instruction (like halt) which would interfere with others. (2) User code cannot access physical memory belonging to the operating system or another user. (3) User code cannot access physical devices including files residing on disk. c) Historically, code that was part of the operating system proper was designed to execute with the CPU in kernel mode, while utilities, compilers, and user applications alway execute in user mode. (1) Today, though, a trend in operating system design is to have only certain portions of the operating system (commonly called the kernel) execute in kernel mode, while the rest of the operating system executes in user mode. (2) This reduces the risk of catastrophic failure resulting from an error in operating system code. (3) It also reduces security vulnerabilities - worms, viruses and the like sometimes rely on getting the CPU to execute their own code in kernel mode. d) So what does user code do when it needs to perform an operation that can only be performed in kernel mode? (1) It places a description of what it wants done in some systemspecific place. 4

(2) It then executes a special instruction (commonly called a system call) that both changes the CPU to kernel mode and begins executing operating system code that analyzes the user code s request and carries it out if it is permissible. e) Some CPU s provide more than two modes to allow finer-grained specification of access privileges - but we will not discuss this further. 2. A second key notion is the notion of an interrupt or trap. a) The two terms interrupt and trap have distinct technical meanings, but are handled similarly, and the one term interrupt is often used collectively to cover both. (1) An interrupt is an event that is triggered by an external device - e.g. when an IO operation to a device is complete, or when a hardware clock ticks. In the case of an IO interrupt, there is typically some process in the waiting state that is waiting for the operation to complete. (2) A trap is a CPU event that is triggered by the program currently running on the CPU. There are two sources for traps. (a) It may be the result of some kind of fault such as executing an illegal instruction or attempting to access a protected region of memory or an IO device. (b) It may be deliberately triggered by the system call instruction. All CPU architectures include some instruction like this, which the hardware treats as an illegal instruction (thus initiating fault processing), but the OS recognizes as a system call rather than a fault. b) Either sort of event is handled by the hardware in essentially the same way: (1) The hardware saves minimal information about the current state of the system - at least the program counter and its current mode (user or kernel), and sometimes a bit of other information. (Details vary from architecture to architecture). (2) The hardware changes mode to kernel 5

(3) The hardware starts executing appropriate OS kernel code. (a) On some hardware architectures, the code that is executed is a dispatcher routine in the OS that analyzes the cause of the interrupt/trap and passes control to the correct handler routine in the OS. (b) On other architectures, this analysis is effectively done by the hardware. (c) In either case, the end result is that the hardware begins executing an appropriate handler routine in the OS. There is one handler for each external device that might cause an interrupt, and one handler for each possible cause for a trap. c) However, what the OS handler routine does depends on the nature of the interrupt or trap. (1) In the case of interrupts from an IO device, the typical actions include: (a) Changing the state of the process waiting for the IO operation to complete from waiting to ready. (b) Possibly initiating a new IO operation on the same device, if there is one waiting. (On a shared device like a disk, one process may request an operation while the device is busy serving another process - in fact, there may be a whole queue of pending requests for a device.) (2) An internal clock tick may result in some process that was waiting a specific period time becoming ready. (3) In the case of traps resulting from a fault, one of the following is done: (a) Initiating appropriate exception processing in the process (b) Terminating the offending process. (4) In the case of a trap resulting from a request for a system service: (a) Prior to initiating the trap, the process will have placed information about what it wants in some appropriate place. 6

(b) The system service handler will analyze this information to determine what the process wants and to see if it is legitimate. If it is legitimate, processing will be initiated; if it is not legitimate, the request will be handled as if it were a fault. d) In any case, after processing the interrupt or trap, the OS handler will have to decide whether to resume running the process that was running at the time the trap occurred, or to run some other process - e.g. because a waiting process of higher priority has just become ready, or because the running process has requested an operation for which it must wait. 3. The book also talked about hardware facilities for memory management. Because we talk about these in CPS311, we will discuss neither these facilities nor the memory management functions of an operating system in this course. B. One of the key responsibilities of the operating system is to manage a collection of processes. 1. A process is a program in execution. At any given time, the status of a process includes: a) A region of memory that contains the code that it is executing. plus the values of its variables. b) Its state. At any given time, a process may either by ready to use the CPU, or waiting for some event to occur before it can proceed further c) The contents of the various CPU registers - particularly the program counter, which indicates the location in memory of the instruction the process is about to execute next. d) Note the difference between a program and a process - a process is a program in execution. (1) When a program is running, there is generally a one-to-one correspondence between the program and the process running it. (2) However, it is possible that some programs, when run, may give rise to multiple processes. 7

(3) Conversely, a single process may run different programs over the course of its life. e) Actually, it is possible on newer systems for a process to be decomposed into a set of threads, each of which has its own set of register values and state, though all share the same memory. We will ignore this for now, but come back to it later. 2. At any given time, a system may running several types of processes. a) Some processes are providing service directly to users - e.g command interpreters, application programs, utilities. Example: as I am writing this, at least three processes I am aware of are currently running on my computer - one running my word processor, my email program, and a web browser. b) Some processes may be server processes providing services to other computers on the network. c) Others processes are providing operating system functions that the user may not be consciously aware of. 3. The kernel provides a number of services concerned with the management of processes - e.g. services that create processes, allow processes to terminate (either normally or in error) and (sometimes) that allow processes to communicate with or control other processes. C. Another major task of the operating system is resource allocation. There is a sense in which the various processes on the system are in competition for various system resources, and it is the kernel's task to apportion them appropriately. 1. One such resource is the CPU. a) On a one-cpu system, only one process can actually be executing on the CPU at a time. (If the system has multiple CPU s or is multicore, the number may be greater than one but still typically much less than the number of processes in existence). b) If there are multiple processes that could use the CPU, the operating system must determine which process gets it, and for how long. 2. Memory is another resource to be allocated. Each process needs one or more regions of memory to hold its code and data. 8

3. Another resource to be managed is the various IO devices. a) One user at a time devices b) The file system c) Network connections. D. Another kernel task is providing support services needed by processes. These include: 1. Support for IO operations, so that application programs can be shielded from hardware-specific details. This can be very sophisticated on windowing systems, where a single physical display is shared by multiple processes through individual windows that can overlap one in various ways. 2. File system management (directory structures, etc.) 3. Networking to other systems. 4. Of course, the operating system should also guarantee processes protection from interference by other processes. E. The heart of the operating system is a collection of routines that are normally entered as a result of hardware interrupts or traps. 1. Most of the time the CPU is executing code on behalf of a user process. 2. The operating system contains a collection of handlers. The execution of one of these is triggered by an external interrupt, or a fault or a system service request by the currently running program. 3. In either case, after servicing the event, the OS handler code resumes the running of some user process. III. Libraries - the API A. All operating systems provide a collection of routines that can be used by application programs - commonly called the API. B. An operating system API includes routines that correspond directly to the various system services, but provide a more straightforward interface. 9

Example: On Unix systems, each of the system service calls is given a number, which is specified (together with other parameters) when the system service is invoked. For each system service, the API also defines a routine that takes the correct number of arguments and supplies the service number. For example, the function read() with three arguments executes a trap with code 3 - which corresponds to the read system service. C. Typically, an API also provides a large number of routines that provide more general support application programs (including things like mathematical functions as well system type operations.) 1. For example, there is a family of IEEE standards for Unix and Unixlike API s known as POSIX (Portable Operating System Interface [for Unix] a) Most versions of Unix (including MacOSX) fully support POSIX. b) Linux mostly supports POSIX c) Microsoft provides an add-on for some versions of Windows that provides full support for the POSIX API. 2. Both Windows and MacOS include extensive libraries as part of the OS distributiion D. There is a somewhat blurry line between API libraries and middleware. The term middleware refers to an add-on API that facilitates cooperation between processes, possibly running on multiple machines. PROJECT APPLICATIONS MIDDLEWARE OPERATING SYSTEM 10

1. Examples: Microsoft.NET, web servers, Object-request brokers, remote procedure call facilities, etc. 2. In practice, the line is often drawn between the API furnished by the operating system, per-se, and that furnished by add-on software - so we get a situation that looks like this: IV. System Programs A. Operating Systems also include a collection of system programs thar can be run when needed. (When such a program is running it gives rise to a process that the kernel manages like other processes.) B. One important kind of system program is the program that provides the user interface to the rest of the system. 1. This can take on of two forms a) A command interpreter that reads textual commands and performs them. DEMO: Shell b) A graphical user interface 2. Systems often provide several interfaces like this that the user can choose from. a) On both the Macintosh and Windows, the normal user interface is via a GUI. b) But on both systems, it is possible to access a command-line interface (as was just demonstrated on a Macintosh). c) On Unix/Unix-like systems, the system can be configured to start up with either a command-line or a GUI interface, but it is always possible to access a command-line when running a GUI interface. d) In the Unix world, the command line is known as the shell, and Unix or Unix-like systems often include a number of different shells that the user can choose from. (1) Both our Linux machines and Mac OSX have the following shells 11

(a) The Bourne shell (named after its developer Steven Bourne) - (known by the name sh) (b) A GNU-variant known as the Bourne again shell (bash) (c) The Korn shell (ksh) (d) The C-Shell - a shell with syntax that resembles the C programming language (csh) (e) A variant of the C Shell (tcsh) (f) The Z shell (zsh) (2) Unix shells have many of the features of a programming language, making it possible to create shell scripts in which the primitive operations are actually the execution of various programs 3. The user interface (whether a GUI or a command line) allows the user to perform various file system operations (e.g examining directories, moving, renaming, or deleting files) as well as to run programs. a) In a GUI, these capabilities are typically part of the GUI. b) With a shell, they may be built into the shell, or provided by system programs that the shell runs. Example: to delete a file on a Unix-like system, one uses the shell command rm, which runs a program known as rm. C. Other system programs support the user interface or provide other utility or administrative services. Example: Show /Applications/Utilities on a Macintosh - describe/demo a few programs Example: Show System Preferences on the Macintosh - describe/demo a few panes 12