Transcript
Page 1: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.1Operating System Concepts

Operating Systems

Lecture 4System Calls

OS System Structure

Page 2: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.2

Computing Environments Traditional Computing Client-Server Computing Peer to Peer Computing (e.g. Napster) Web-based Computing Special Purpose Systems:

Embedded Systems Multimedia Systems Handheld Systems

Operating System Concepts

Client Server Computing

Page 3: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.3

User-Operating System Interface Command Line Interpreter (CLI) (e.g. UNIX or MS-DOS)

Fetches command from user and executes Commands may be built into O.S. or names of programs to

execute.

Operating System Concepts

Bourne Shell Command Interpreter for Solaris

Page 4: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.4

User-Operating System Interface--GUI

GUI uses desktop metaphor with Icons for files and folders. Actions executed with mouse-over and button-clicks. Many systems provide both CLI and GUI (e.g. LINUX has

desktop environment, Apple UNIX shell, Windows has CLI shell).

Operating System Concepts

Mac OS X GUI

Page 5: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.5Operating System Concepts

System Calls

System calls provide the interface between a running program and the operating system.Generally available as assembly-language

instructions. Languages defined to replace assembly language for

systems programming allow system calls to be made directly (e.g., C, C++)

Use API's so don't need to know system details. (Win32, POSIX, Java)

Page 6: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.6Operating System Concepts

System Calls are Used Frequently

A single program may make numerous system calls. For example, a program to read from one file and write to another would need system calls for the following:(We will discuss this in class)Prompt the user to enter file namesRead in filenamesOpen input fileRead from input fileOpen/create output fileWrite output to fileClose input and output files

The system must be able to signal and handle errors that occur.

Page 7: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.7Operating System ConceptsOperating System Concepts

C program invoking printf() library call, which calls write() system call

API system call

Page 8: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.8Operating System Concepts

Passing Parameters

Three general methods are used to pass parameters between a running program and the operating system.Pass parameters in registers.Store the parameters in a table in memory,

and the table address is passed as a parameter in a register.

Push (store) the parameters onto the stack by the program, and pop off the stack by operating system.

Page 9: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.9Operating System Concepts

Passing of Parameters As A Table

Page 10: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.10Operating System Concepts

Types of System Calls Process control

create (fork), execute (exec), wait, end (exit), abort (kill), etc. File management (Can you think of any in Linux?)

create (mkdir), delete (rm, rmdir), open, close, read, write, cp, rm, mkdir, rmdir, ls, cat, more, grep, etc. get/set file attributes

Device management read, write, attach (mount), detach (unmount), get/set device

attributes Information maintenance

get/set time or date, get/set process/device attributes (getpid, du, ps, etc)

Communications send, receive, connect, accept, get/set status information,

gethostid/sethostid, gethostbyname, etc. Protection (Can you think of any?)

get/set file attributes (chmod, chown, chgrp)

Page 11: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.11Operating System Concepts

Process Control

A process executing one program may want to load and execute another program (e.g. the shell loads and executes programs). The following are important considerations:

Where does control return when the new process is finished? If return control to existing program, must save memory image

of existing program before loading new process. If both programs are to run concurrently, the new process is

added to the multiprogramming set of processes. Controlling execution of the process:

get/set process attributes, terminate process Waiting for the process to finish

wait event, signal event Terminating the process

Normal (exit) or abnormal (abort) termination. There are multiple ways of implementing process control.

Page 12: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.12Operating System Concepts

MS-DOS Execution

At System Start-up Running a Program

MS-DOS runs the command interpreter on startup.

It loads a new program into memory, writing over part of the interpreter.

When the program terminates, the part of the interpreter not overwritten begins execution. It loads the rest of the interpreter from disk.

Page 13: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.13Operating System Concepts

UNIX Running Multiple Programs

UNIX runs the shell on startup.

To start a new process, it uses the fork command to create the process and exec to execute it.

If the process is in the foreground, the shell waits for the process to finish.

If the process is in the background, the user can continue to issue commands while the process is running.

When the process is finished, it executes an exit system call.

Page 14: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.14

System Calls--Communication

Operating System Concepts

How is inter-process communication achieved? Message Passing (think USPS):

• Good for small amounts of data• No conflicts (i.e. with protection and

synchronization)• Easier to implement

Shared Memory• Speed• Convenience

Both are common and most systems have both.

Page 15: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.15Operating System Concepts

Message Passing

Processes use message passing to send messages to one another.

First, the connection must be opened. The name of the communicator must be known (host name or

host id, process name or process id). Use get process id or get host id.

open connection, close connection

The recipient uses "accept connection" The initiator is the client. The recipient of the request is

the server. Exchange of information made with write message

system calls.

Page 16: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.16Operating System Concepts

Shared Memory

In memory sharing, processes communicate by writing and reading to the same memory addresses.

Processes use map memory system calls to access memory owned by other processes.

Both processes must agree to remove O.S. memory restriction so that they can access the same region of memory.

The processes are responsible for the form and location of the data.

The processes are responsible for making sure that they are not writing to the same memory area simultaneously.

Page 17: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.17Operating System Concepts

Communication Models

Msg Passing Shared Memory

Communication may take place using either message passing or shared memory.

Page 18: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.18Operating System Concepts

System Programs

System programs provide a convenient environment for program development and execution. The can be divided into: File manipulation (copy, delete, rename, print, list) Status information (get date, disk usage, performance info) File modification (text editors) Programming language support (compilers, interpreters,

debuggers) Program loading and execution (loaders, linkers) Communications (IM, email, remote login) Application programs

Most users’ view of the operation system is defined by system programs, not the actual system calls.

Page 19: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.19

Types of OS Structure

Operating System Concepts

The design of operating systems has evolved over time.We can roughly divide them into the following categories:

1. Monolithic systems (1st operating systems).

2. Modular systems (e.g. early UNIX, Solaris)

3. Hierarchical layered systems (e.g. OS/2)

4. Microkernel systems (e.g. Mach)

5. Virtual Machines

Page 20: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.20

From monolithic to modular

Operating System Concepts

Monolithic systems: No structure to speak of. As the OS grows, the complexity becomes overwhelming. Example: OS/360 version 1

created by 5000 programmers over 5 years. In 1964, had over 1 million lines of code.

Example: Multics In 1975, had over 20 million lines of code. When UNIX was written, people joked it was EUNUCHS, i.e. a castrated Multics

Modular systems: Divide OS into modules. Example: Original UNIX had 2 modules.

System programs (e.g. emacs, compiler) The kernel (HUGE!)--file system, CPU scheduling, memory management, etc.

Problem: Kernel so big and complex that it was hard to work with and extend.

Page 21: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.21Operating System Concepts

MS-DOS System Structure

MS-DOS – written to provide the most functionality in the least space not divided into modulesAlthough MS-DOS has some structure, its

interfaces and levels of functionality are not well separated

Page 22: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.22Operating System Concepts

MS-DOS Layer Structure

Page 23: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.23Operating System Concepts

UNIX System Structure

UNIX – limited by hardware functionality, the original UNIX operating system had limited structuring. The UNIX OS consists of two separable parts. Systems programs The kernel

Consists of everything below the system-call interface and above the physical hardware

Provides the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level.

Page 24: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.24Operating System Concepts

UNIX System Structure

Page 25: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.25Operating System Concepts

Layered Approach

The operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface.

With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers.

Advantage: Modularity makes it easy to modify and extend.

Disadvantage: Some functions may depend on one another, making a strict hierarchy difficult to implement.

Page 26: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.26Operating System Concepts

An Operating System Layer

Page 27: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.27Operating System Concepts

OS/2 Layer Structure

Jointly developed in the mid 1980's by IBM and MS

Page 28: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.28

Modules

Operating System Concepts

Most modern operating systems implement kernel modules• Uses object-oriented approach• Each core component is separate• Each talks to the others over known

interfaces• Each is loadable as needed within the

kernel

Overall, similar to layers but with more flexible

Page 29: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.29

Solaris Modular Approach

Operating System Concepts

Page 30: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.30Operating System Concepts

Microkernel System Structure

Moves as much from the kernel into “user” space. Communication takes place between user modules

using message passing. Only the kernel is machine/device dependent.

Example: Mac OS X is based on the Mach micro kernel.

Page 31: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.31

Microkernels—Benefits and Drawbacks

Operating System Concepts

Microkernels:Advantages:

Modularity (Easy to modify modules) Extensibility (Can easily add new functions--user processes) Flexibility (Can remove functions that are not needed) Portability (Only the small kernel has hardware specific code) Distributed System support (Message passing can generalize to network communications) Object oriented (A good design).

Disadvantages: (will discuss in class) Performance: create/send receive message takes longer than a system call. Efficiency still a problem.

Page 32: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.32Operating System Concepts

Virtual Machines

Virtual Machines: Provides software interface identical to underlying bare hardware.

Virtual CPU, Virtual Device drivers, Virtual memory, etc. Each process has its own virtual machine Implementation provides interface between virtual machine and real machine. Physical resources divided up between the virtual machines (e.g. minidisks). Advantages: (will discuss in class)

Security (no process has direct access to system resources.) System development (Can use virtual machine to test new OS) System compatibility. Can run Windows on Virtual PC on Mac. Java runs on Java virtual machine--cross platform.

Disadvantage: (will discuss in class) Speed: Each instruction is interpreted. This is slower than a direct system call.

Page 33: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.33Operating System Concepts

Virtual Machine Diagram

Non-virtual Machine Virtual Machine

Page 34: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.34

VMWare Architecture

Operating System Concepts

Page 35: Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, 2011 3.1 Operating System Concepts Operating Systems Lecture 4 System Calls OS System

Silberschatz, Galvin and Gagne 2002Modified for CSCI 346, Royden, 2011

3.35Operating System Concepts

Java Virtual Machine

Compiled Java programs are platform-neutral bytecodes executed by a Java Virtual Machine (JVM).

JVM consists of

- class loader

- class verifier

- runtime interpreter

Just-In-Time (JIT) compilers increase performance


Recommended