19
1 Lecture 3: OS Functions and Design Approaches OS duties process management memory management disk/file management protection & security interaction with OS dual-mode operation system calls API, system programs, UI OS design approaches: monolithic kernel microkernel virtual machine

1 Lecture 3: OS Functions and Design Approaches OS duties process management memory management disk/file management protection & security interaction

Embed Size (px)

Citation preview

Page 1: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

1

Lecture 3: OS Functions and Design Approaches

OS duties

• process management

• memory management

• disk/file management

• protection & security interaction with OS

• dual-mode operation

• system calls

• API, system programs, UI OS design approaches:

• monolithic kernel

• microkernel

• virtual machine

Page 2: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

2

Process Management

OS manages many kinds of activities:

• user programs

• system programs: printer spoolers, name servers, file servers, etc. a running program is called a process

• a process includes the complete execution context (code, data, PC, registers, OS resources in use, etc.)

• a process is not a program program - a sequence of instructions (passive) process - one instance of a program in execution (active);

• many processes can be running the same program and one program may cause to create multiple processes

from OS viewpoint process is a unit of work; OS must:

• create, delete, suspend, resume, and schedule processes

• support inter-process communication and synchronization, handle deadlocks

Page 3: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

3

Memory Management primary (main) memory (RAM)

• provides direct access storage for CPU

• processes must be in main memory to execute OS must:

• mechanics keep track of memory in use keep track of unused (“free”) memory protect memory space allocate, deallocate space for processes swap processes: memory disk

• policies decide when to load each process into memory decide how much memory space to allocate to each process decide when a process should be removed from memory

Page 4: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

4

Disk Management

the size of the disk is much greater than main memory and, unlike main memory, disk is persistent (survives system failures and power outages)

OS hides peculiarities of disk usage by managing disk space at low level:

• keeps track of used spaces

• keeps track of unused (free) space

• keeps track of “bad blocks” OS handles low-level disk functions, such as:

• schedules of disk operations

• and head movement

Page 5: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

5

File Management

disks provide long-term storage, but are awkward to use directly

file - a logical named persistent collection of data maintained by OS file system - a logical structure that that is maintained by OS to simplify file

manipulation; usually directory based OS must:

• create and delete files and directories

• manipulate files and directories - read, write, extend, rename, copy, protect

• provide general higher-level services - backups, accounting, quotas note the difference between disk management and file system management

Page 6: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

6

Protection & Security

protection – any mechanism for controlling access of processes or users to resources

• disk, memory, CPU, security – defense of the system against internal and external attacks

• systems generally first distinguish among users, to determine who can do what user identities and privileges associated with this identifier user ID then associated with all files, processes of that user to

determine access control

Page 7: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

7

Dual-Mode Operation

to allow protection OS operates in dual-mode user mode and kernel mode mode bit provided by hardware

• user (1), kernel (0)

• enables OS to distinguish when system is running user code or kernel code

some instructions designated as privileged, only executable in kernel mode

• changing modes

• modifying timers

• modifying interrupt service routines

• I/O device access

Page 8: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

8

System Call Definition

app. program can ask the OS to carry out service forit by invoking a system call

• to the application the invocation is similar to an ordinary function call

• example: Unix write system call description

prompt% man -S 2 write

WRITE(2) Linux Programmer's Manual WRITE(2)

NAME write - write to a file descriptor

SYNOPSIS #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count);

DESCRIPTION write() writes up to count bytes to the file referenced by the file descriptor fd from the buffer starting at buf. …

RETURN VALUE On success, the number of bytes written are returned …

Page 9: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

9

Mode Switch mode switch – transition from user to kernel mode system call generates a trap (software generated

interrupt) physical interrupt occurs (e.g. a timer interrupt) control is transferred to the interrupt service routine, which may

pass control to the OS (in kernel mode) return it back to the user process

in case OS needs to do extensive work, it needs to save the context (state) of the user program

Page 10: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

10

Function Invocation TraceAcross Modes

Example function invocation in Solaris (Unix-like OS from Sun Microsystems)

• node the mode (User or Kernel) for function invocation

Page 11: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

11

System Call Example a typical app. program invokes system calls repeatedly example: copying a file

Page 12: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

12

Application Program Interface

“raw” system calls tend to be difficult to use application program interface (API) defines functions that are more

convenient to use API functions

• can be invoked by app. programmer

• run in user mode

• directly invoke system calls

• implemented in system libraries that come with the OS and are linked to the app. program

API examples: POSIX API (implemented by most Unix systems, MacOS X), Java API, Win 32 API – windows

• ex: printf (C function that prints formatted output, part of POSIX API) repeatedly invokes write

Page 13: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

13

System Programs and UIs

system programs come with the OS

• they are designed for end users – the personfor whom the computer/OS/app. programs are designed cf. application programmers, OS programmers

• operate in user mode

• typical tasks: file manipulation, status info, file modification (editors), programming language support (compilers/assemblers), configuration, communication, etc.

user interface (UI) is a way the end-user interacts with system programs (and through them with the OS),

command-line interface (CLI) – interaction through command interpreter (shell) – a text-based system program

graphical-user interface (GUI) – mouse-heavy with a lot of graphics

• most popular OSes support both kinds of UI

Page 14: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

14

Monolithic Kernel OS Design

advantages: speed and ease of operation (everything is at hand) disadvantages:

• hard to develop, maintain, modify and debug

• kernel gets bigger as the OS develops

critical OS data structures and device registers are protected from user programs

system processes

system calls

user processes

device controllers

signalsterminalscharacter I/O

filesswappingdisk, tape

CPU schedulingpage replacementvirtual memory

terminal drivers

device drivers

memory drivers

kernel

machine-independent

machine-

dependent

hardware

app. processes

commands/interrupts

kernelmode

usermode

Page 15: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

15

Modular Kernel

classic monolithic kernel requires all functionality to beinbuilt into kernel and loaded at boot-time – waste of RAM, limited flexibility

loadable kernel module – object file to be loaded at boot time or, possibly compile time

• extends base kernel functionality, common functions of kernel modules device drivers/bus drivers, filesystems, system

calls, CPU scheduling classes, executable file formats

• loaded to kernel address space has full access to all kernel memory

• has defined programming interface, possibly protected Linuxes, Windows, Solaris, Mac OS X support kernel

modules

Page 16: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

16

Microkernel

advantages: reliability, ease of development, modularity - parts can be replaced and tailored to the architecture, user requirements etc.

disadvantages: slow? examples: MacOS X, Windows XP

• small kernel implements communication (usually messages) • when system services are required microkernell calls other parts of OS running in user modes and passes the request there

user processes

filesystem

CPUscheduling

threadsystem

networksupport

paging

system processes

micro-kernel

usermode

kernelmode

communication protection low-level VM processor control

device controllers

hardware commands/interrupts

Page 17: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

17

Virtual Machine

OS’s system callsare considered an enhancement ofhardware’sinstruction set• extend further –

virtual machine each user task is

provided with an abstract (virtual machine) which OS + hardware implement• IBM – pioneered• modern examples:

Java VM – next slide VMware Player – extra guest/host bit, guest OS executes limited set of instructions, if different instruction –

trap to host OS

adv. – portability at binary-level, security, greater language flexibility

dis. – speed(?)

Page 18: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

18

Java Virtual Machine (JVM) Java source code is translated into an architecture

independent java bytecode bytecode is executed by JVM JVM can be implemented purely in software or in hardware JVM verifies bytecode’s correctness and then either interprets (translates the

code into machines instructions one by one) or just-in-time (JIT) compiles to optimize, or both

adv. – portability at binary-level, security, greater language flexibility

dis. – speed(?)

Page 19: 1 Lecture 3: OS Functions and Design Approaches  OS duties process management memory management disk/file management protection & security  interaction

19

Lecture Review

major OS duties are

• process management

• memory management

• disk/file management OS interacts with users through system calls, to ease interaction

• API - for app. programmers

• GUI or CLI for end-users OS is a big and complex program; traditional monolithic kernel

design approach yields OSes that are fast but hard to develop, modify and debug; other approaches have been suggested:

• microkernel

• virtual machine