operating systems {week 05}

Download Operating Systems {week  05}

Post on 23-Feb-2016

37 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D. Operating Systems {week 05}. Operating system structure (i). Using a layered approach, the operating system is divided into N levels or layers Layer 0 is the hardware Layer 1 is often the kernel - PowerPoint PPT Presentation

TRANSCRIPT

Chapter 1: Information Technology

Operating Systems{week 05}Rensselaer Polytechnic InstituteCSC 432 Operating SystemsDavid Goldschmidt, Ph.D.Operating system structure (i)

Using a layered approach, the operating system is divided into N levels or layers Layer 0 is the hardwareLayer 1 is often the kernel Layer N is the top-leveluser interface (GUI)Each layer uses functionsand services of the layer(or layers) beneath itOperating system structure (ii)Also viewas a stack of services

Operating system kernelThe core program running inan operating system is calledthe kernel When a computer is switched on,a bootstrap program executes from ROMThe bootstrap program initializes the system, then loads the operating system kernel and starts its execution

User and kernel modes (i)Program instructions run eitherin user mode or in kernel mode Kernel mode allows the operating systemto protect itself and its system components

switch modesvia system callsUser and kernel modes (ii)Kernel gives control to a user process, but may set a timer to ensure a process does not run beyond its allotted timeTo avoid infinite loops, memoryleaks, memory hogs, etc.Not always effective in practice...Can you stop a runaway processbefore your computer crashes?

Aaaaaaaugghhhh!Im going to takethis computer and...System calls via APIs (i)OS services are available via system calls System calls are made via an interface calledan Application Program Interface (API)Common operating system APIs:Win32 API for WindowsPOSIX API for POSIX-based systems,including UNIX, Linux, Mac OS XJava API for Java Virtual MachineC/C++ Standard Library

System calls via APIs (ii)Types of system calls include:Process control (e.g. start/suspend/stop a process)Debugging information, tooFile managementDevice managementInformation retrieval and maintenanceCurrent date/time, number of current users, OS version, amount of free memory, process information, etc.Communications (e.g. IPC, network)

System calls via APIs (iii)An API hides the implementation details of the underlying operating systemProgrammers just need to abide bythe API specifications How do we change the API orthe operating system servicesthat it offers?

the dude abides...System calls via APIs (iv)

System calls via APIs (v)Example using the printf()function from C

One API may callanother, which mayin turn call another,and so on...System calls via APIs (vi)Use registers to pass parameters:Store memory location X that references a block of data somewhere in memory

Operating system services (i)An operating system provides services:Program executionLoad programs into memory, run/suspend/halt programs, handle/display errorsI/O operationsSeamlessly interact with I/O devices, includingdisks, networks connection, etc.Filesystem manipulationRead/write/traverse filesystem directories,read/write files, enforce permissions, search for files

Operating system services (ii)Other operating system services:Inter-Process Communications (IPC)Processes exchange information via shared memory,message passing, sockets, pipes, files, etc.Often spans multiple computers and networksError detection and recoveryDetect errors in CPU, memory, I/O devices,processes, network connections, etc.Recover from errors gracefully,ensuring correct and consistent operations

Multiprogramming and timesharingMultiprogramming goals:Maximize CPU utilizationMaximize number of processes in memory

Timesharing goals:Switch CPU among processes such that users interact with each program simultaneouslyMaximize fairnessalmost!Process scheduling and queuesProcesses are created bythe operating systemProcesses initially added toa job queue, which containsall processes waiting to enter the systemFrom the job queue, processes thatare ready for execution are addedto the ready queue

SchedulersA long-term scheduler (i.e. job scheduler) selects processes from the job queue, adding those processes to the ready queue

A short-term scheduler (i.e. CPU scheduler) selects processes from the ready queueand allocates time with the CPUMore on this later....

Long-term scheduling (i)The long-term scheduler isinvoked infrequently

Long-term scheduling (ii)The degree of multiprogramming ofan operating system is defined asthe number of processes in memoryIn a stable operating system,the average process arrival rate equalsthe average process departure rateLong-term scheduling (iii)Processes are either I/O bound or CPU bound A CPU-bound process does little I/O and instead makes heavy use of the CPUAn I/O-bound process spends a majority of itstime performing (i.e. waiting for) I/O

The long-term scheduler should select a good process mix of CPU-bound and I/O-bound processesLong-term scheduling (iv)Most modern operating systems have no long-term scheduler (e.g. Windows, UNIX)All processes are admitted tothe ready queue, regardlessof whether the operatingsystem can handle the loadOften results in userschanging their usage habits....

Medium-term schedulingModern operating systems implement a medium-term scheduler to swap processes to/from memory and disk

Processes (i)A process is an active program in executionRequires CPU time, memory, file access,network access, other I/O access

Operating system is responsible for:Creating/deleting processesScheduling processesAllocating resources to processesSynchronizing communication between processes

Processes (ii)For each process, the operatingsystem manages and executesprocesses by recording:Program counter (PC)RegistersData section (global data)Stack (temporary data)Heap (dynamically allocated memory)

heapstackdatatext/codeProcess statesAs a process executes, it changes its state

Process control blockOperating system represents each process via a process control block (PCB)Process stateProcess ID or numberProgram counter (PC)CPU registersCPU-scheduling and memorymanagement informationList of open file/resource handles

Process context switch

context switch takesa few millisecondsProcess scheduling

Short-term schedulingThe short-term scheduler frequently decides which process the CPU executes nextTypical time slice (t) a process has withthe CPU is 100 millisecondsHow much CPU time is wastedif t is 100ms and it takes 10msto schedule the next processand perform the context switch?

Process creation (i)Processes are created from other processesA parent process creates a child process, whichin turn creates child processes of its own, etc.A tree of processes is the result:

Process creation (ii)Operating system resources are sometimes shared amongst processes

Possibilities:Parent and child processes share all resourcesChild shares a subset of its parents resourcesParent and child processes share no resources

Process creation (iii)Each process has itsown unique processidentifier (pid)Process creation (iv)When a new process is created,the parent has two options:Parent process continues to execute concurrently with its childrenParent process waits for its children toterminate their execution

The child process decides what it will do:Duplicate the parent or load a new program

Process creation (v)In Unix, a new child process is forked viathe fork() system call

Child optionally calls the exec() system callto load a new program