27
Ch2. System Structures Ch2. System Structures Operating System Concept 8 Operating System Concept 8 th th ed. ed. 2009. 10. 24 2009. 10. 24 In-Bon Kuh In-Bon Kuh GNU OSLab. GNU OSLab.

Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Embed Size (px)

Citation preview

Page 1: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Ch2. System StructuresCh2. System StructuresOperating System Concept 8Operating System Concept 8thth ed. ed.

2009. 10. 242009. 10. 24

In-Bon KuhIn-Bon Kuh

GNU OSLab.GNU OSLab.

Page 2: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 22

ContentsContents

Ch2. System StructuresCh2. System Structures1. Operating-System Services2. User Operating-System Interface3. System Calls4. Types of System Calls5. System Programs6. Operating-System Design and Implementation7. Operating-System Structure8. Virtual Machines9. Operating-System Debugging10. Operating-System Generation11. System Boot12. Summary

Page 3: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 33

Chapter ObjectivesChapter Objectives

To describe the services an operating system provides to users, To describe the services an operating system provides to users, processes, and other systems.processes, and other systems.

To discuss the various ways of structuring an operating To discuss the various ways of structuring an operating system.system.

To explain how operating systems are installed and To explain how operating systems are installed and customized and how they boot.customized and how they boot.

Page 4: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 44

2.1 Operating-System Services2.1 Operating-System Services

user and other system programsuser and other system programs

operating systemoperating system

hardwarehardware

GUIGUI batchbatch command command lineline

user interfaceuser interface

system callssystem callssystem callssystem calls

ServicesServicesServicesServices

programprogramexecutionexecutionprogramprogramexecutionexecution

I/OI/Ooperationsoperations

I/OI/Ooperationsoperations

filefilesystemssystems

filefilesystemssystems

communicommunicationcation

communicommunicationcation

resourceresourceallocationallocationresourceresourceallocationallocation accountingaccountingaccountingaccounting

errorerrordetectiondetection

errorerrordetectiondetection

protectionprotection& security& securityprotectionprotection& security& security

Page 5: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 55

2.3 System Calls2.3 System Calls

$ cp sfile dfile

How system calls are usedHow system calls are usedAcquire input file name Write prompt to screen Accept inputAcquire output file name Write prompt to screen Accept inputOpen the input file if file doesn’t exist, abortCreate output file if file exist, abortLoop Read from input file Write to output fileUntil read failsClose input and output filesWrite completion message to screenTerminate normally

Page 6: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 66

API (Application Programming Interface)API (Application Programming Interface)

– A set of functions available to an application programmer

– Portable and easy to work

– Most common APIs

– Win32 API, POSIX API, Java API

BOOL ReadFile( HANDLE file, LPVOID buffer, DWORD bytesToRead,LPDWORD bytesRead, LPOVERLAPPED ovl );

ssize_t read(int fd, void *buf, size_t count);

int read(char[] cbuf, int offset, int length);

Win32 API

POSIX API

Java API

Page 7: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 77

System-call interfaceSystem-call interface

System call interfaceSystem call interfaceUser mode

Kernel mode

open()open()

User ApplicationUser Application

open()

return......

..

..

..

ith

Page 8: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 88

User mode

Kernel mode

write() system callwrite() system call

write()

<< Standard C Library, an example of system-call interface >>

#include <stdio.h>int main() { … printf(“Greetings”); … return 0;}

Standard C LibraryStandard C Library

Page 9: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 99

2.4 Types of System Calls2.4 Types of System Calls

Windows Unix

Process Control CreateProcess()ExitProcess()WaitForSingleObject()

fork()exit()wait()

File Manipulation CreateFile()ReadFile()WriteFile()CloseHandle()

open()read()write()close()

Device Manipulation SetConsoleMode()ReadConsole()WriteConsole()

ioctl()read()write()

Information Maintenance GetCurrentProcessID()SetTimer()Sleep()

getpid()alarm()sleep()

Communications CreatePipe()CreateFileMapping()MapViewOfFile()

pipe()shmget()mmap()

Protection SetFileSecurity()InitializeSecurityDescriptor()SetSecurityDescriptorGroup()

chmod()umask()chown()

Page 10: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 1010

Process ControlProcess Control

– single-tasking system

boot kernel shell process shell

free memory

process

shell

kernel

free memory

free memory

kernel

free memory

shell

kernel

free memory

shell

kernel

memorylayout

executionflow

Page 11: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 1111

– multi-tasking system

boot kernel shell shell shell process C

free memory

process A

shell

kernel

free memory

free memory

kernel

free memory

shell

kernel

process A

free memory

process B

process A

shell

kernel

process B

free

process C

process B

freememory

shell

kernel

memorylayout

executionflow

Page 12: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 1212

File ManagementFile Management

file name

Attributes

file type

accounting information

protection codes

DIRECTORYContents

file name

Attributes

file type

accounting information

protection codes

FILEContents

createopendeletecloseget file attributeset file attribute

createopendeletecloseget file attributeset file attribute

readwritereposition(lseek)

readwritereposition(lseek)

Page 13: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 1313

Device ManagementDevice Management

Device Abstraction

Device file

physical device

request

release

…fd = open(“/dev/lp”, …);write(fd, “Greeting!”, …);…

…fd = open(“/dev/lp”, …);ioctl(fd, CONTROL, …);…

contention

Page 14: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 1414

host Bhost A

CommunicationCommunication

process A process B

Network

connect, wait, send, receive, close, …

process A process B …

shared region

memory

create attach

<< Message-Passing Model >> << Shared-Memory Model >>

Page 15: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 1515

Information MaintenanceInformation Maintenance

– system information

– time, date, users, memory, version number, …

– debugging facility

– memory dump, trace, single stepping, …

– profiling

– statistics for consumption of time and space ProtectionProtection

– controlling access to resources

– setting/getting permissions, allow/deny users, …

Page 16: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 1616

2.5 System Programs2.5 System Programs

Categories Programs

File management create, delete, copy, rename, print, dump, list, and manipulate files/directories

Status information ask for date, time, memory, disk and users information

File modification text editors, searching command

Programming-language support

compilers, assemblers, debuggers, and interpreters

Program loading & execution

absolute loaders, relocatable loaders, and linkage editors

Communications email agents, web browsers, terminal clients

Page 17: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 1717

2.7 Operating-System Structure2.7 Operating-System Structure

Simple StructureSimple Structure

ROM BIOS device driversROM BIOS device drivers

MS-DOS device driversMS-DOS device drivers

resident system programresident system program

application programapplication program

solid-combined vulnerable to malicious programs adhere to hardware directly

Page 18: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 1818

Layered ApproachLayered Approach

Page 19: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 1919

MicrokernelsMicrokernels

<< Hybrid Microkernel Model (Mac OS X) >>

Page 20: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 2020

Module ApproachModule Approach

<< Core kernel & modules (Sun Solaris) >>

Page 21: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 2121

2.9 Operating-System Debugging2.9 Operating-System Debugging

““Debugging”Debugging”– the activity of finding and fixing errors, or bugs, in a systemthe activity of finding and fixing errors, or bugs, in a system– a methodical process of finding and reducing the number oa methodical process of finding and reducing the number o

f bugs, or defects, in a computer program or a piece of elef bugs, or defects, in a computer program or a piece of electronic hardware thus making it behave as expected ctronic hardware thus making it behave as expected (from (from wikipedia)wikipedia)

Kernighan’s Law“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”

Page 22: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 2222

Failure AnalysisFailure Analysis

– debugging user-level process code

– log file, core dump (a capture of memory)

– operating system debugging

– log file, crash dump (kernel’s memory state), process dump (for later analysis)

Performance TuningPerformance Tuning

– seeking to improve performance by removing bottlenecks

– add measuring codes

– run interactive monitoring tool

Page 23: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 2323

% cumulative self self total time seconds seconds calls ms/call ms/call name 33.34 0.02 0.02 7208 0.00 0.00 open 16.67 0.03 0.01 244 0.04 0.12 offtime 16.67 0.04 0.01 8 1.25 1.25 memccpy 16.67 0.05 0.01 7 1.43 1.43 write 16.67 0.06 0.01 mcount 0.00 0.06 0.00 236 0.00 0.00 tzset 0.00 0.06 0.00 192 0.00 0.00 tolower 0.00 0.06 0.00 47 0.00 0.00 strlen 0.00 0.06 0.00 45 0.00 0.00 strchr 0.00 0.06 0.00 1 0.00 50.00 main 0.00 0.06 0.00 1 0.00 0.00 memcpy 0.00 0.06 0.00 1 0.00 10.11 print 0.00 0.06 0.00 1 0.00 0.00 profil 0.00 0.06 0.00 1 0.00 50.00 report

<< an example of profiling >>

Page 24: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 2424

– an example of monitoring tools

Topas Monitor for host: AX3 EVENTS/QUEUES FILE/TTYSat Oct 24 08:58:05 2009 Interval: 2 Cswitch 74 Readch 236 Syscall 1484 Writech 520CPU User% Kern% Wait% Idle% Reads 1 Rawin 0ALL 0.1 0.1 0.0 99.8 Writes 2 Ttyout 236 Forks 0 Igets 0Network KBPS I-Pack O-Pack KB-In KB-Out Execs 0 Namei 0en1 0.4 0.5 1.0 0.0 0.3 Runqueue 0.0 Dirblk 0lo0 0.0 0.0 0.0 0.0 0.0 Waitqueue 0.0

Disk Busy% KBPS TPS KB-Read KB-Writ PAGING MEMORYhdisk0 0.0 0.0 0.0 0.0 0.0 Faults 0 Real,MB 7936hdisk1 0.0 0.0 0.0 0.0 0.0 Steals 0 % Comp 11.1cd0 0.0 0.0 0.0 0.0 0.0 PgspIn 0 % Noncomp 1.1 PgspOut 0 % Client 1.1Name PID CPU% PgSp Owner PageIn 0dtgreet 86182 0.1 1.3 root PageOut 0 PAGING SPACEtopas 274676 0.0 1.2 root Sios 0 Size,MB 8192sshd 340058 0.0 1.0 root % Used 0.0gil 69666 0.0 0.9 root NFS (calls/sec) % Free 100.0java 307370 0.0 39.4 root ServerV2 0X 135248 0.0 2.5 root ClientV2 0 Press:rpc.lock 225462 0.0 1.2 root ServerV3 0 "h" for helpaixmibd6 254076 0.0 1.2 root ClientV3 0 "q" to quitnetm 65568 0.0 0.4 rootsyncd 94314 0.0 0.5 rootxmgc 49176 0.0 0.4 root

<< an example of monitoring tools >>

Page 25: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 2525

DTraceDTrace– dynamic, safe, low-impact debugging (both user/kernel)– a broad & a deep tool

– from specific process to system-wide trace– from code lines to CPU instructions

kernel data

PROVIDER

PROVIDER CONSUMERCONSUMERkernel function PROBE

kernel function

...

fire

create

access

transfer

<< DTrace Framwork >>

Page 26: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 2626

<< trace of “ioctl” system call >>

Page 27: Ch2. System Structures Operating System Concept 8 th ed. 2009. 10. 24 In-Bon Kuh GNU OSLab

Operating System Concept 8th edition 2727

sched:::on-cpuuid == 101{ self->ts = timestamp;}

sched:::off-cpuself->ts{ @time[execname] = sum(timestamp –self->ts); self->ts = 0;}

#dtrace –s sched.ddtrace: script ‘sched.d’ matched 6 probes^C gnome-settings-d 142354 gnome-vfs-daemon 158243 dsdm 189804 wnck-applet 200030 gnome-panel 277864 clock-applet 374916 mapping-daemon 385475 xscreensaver 514177 metacity 539281 Xorg 2579646 gnome-terminal 5007269 mixer-applet2 7388447 java 10769137

<< an example D code >> << DTrace result >>