Ch 2 System Structures Operating System Concept 8

  • Slides: 27
Download presentation
Ch 2. System Structures Operating System Concept 8 2009. 10. 24 In-Bon Kuh GNU

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

Contents v Ch 2. System Structures 1. Operating-System Services 2. User Operating-System Interface 3.

Contents v Ch 2. System Structures 1. Operating-System Services 2. User Operating-System Interface 3. System Calls 4. Types of System Calls 5. System Programs 6. Operating-System Design and Implementation 7. Operating-System Structure 8. Virtual Machines 9. Operating-System Debugging 10. Operating-System Generation 11. System Boot 12. Summary Operating System Concept 8 th edition 2

Chapter Objectives v To describe the services an operating system provides to users, processes,

Chapter Objectives v To describe the services an operating system provides to users, processes, and other systems. v To discuss the various ways of structuring an operating system. v To explain how operating systems are installed and customized and how they boot. Operating System Concept 8 th edition 3

2. 1 Operating-System Services user and other system programs GUI batch command line user

2. 1 Operating-System Services user and other system programs GUI batch command line user interface system calls program execution I/O operations file systems communi cation error detection resource allocation accounting protection & security Services operating system hardware Operating System Concept 8 th edition 4

2. 3 System Calls v How system calls are used $ cp sfile dfile

2. 3 System Calls v How system calls are used $ cp sfile dfile Operating System Concept 8 th edition Acquire input file name Write prompt to screen Accept input Acquire output file name Write prompt to screen Accept input Open the input file if file doesn’t exist, abort Create output file if file exist, abort Loop Read from input file Write to output file Until read fails Close input and output files Write completion message to screen Terminate normally 5

v API (Application Programming Interface) – A set of functions available to an application

v API (Application Programming Interface) – A set of functions available to an application programmer – Portable and easy to work – Most common APIs – Win 32 API, POSIX API, Java API BOOL Read. File( HANDLE file, LPVOID buffer, DWORD bytes. To. Read, LPDWORD bytes. Read, LPOVERLAPPED ovl ); Win 32 API ssize_t read(int fd, void *buf, size_t count); POSIX API int read(char[] cbuf, int offset, int length); Java API Operating System Concept 8 th edition 6

v System-call interface User Application open() User mode System call interface Kernel mode return

v System-call interface User Application open() User mode System call interface Kernel mode return . . . ith open(). . . Operating System Concept 8 th edition 7

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

#include <stdio. h> int main() { … printf(“Greetings”); … return 0; } User mode Standard C Library Kernel mode write() system call << Standard C Library, an example of system-call interface >> Operating System Concept 8 th edition 8

2. 4 Types of System Calls Process Control File Manipulation Device Manipulation Information Maintenance

2. 4 Types of System Calls Process Control File Manipulation Device Manipulation Information Maintenance Communications Protection Operating System Concept 8 th edition Windows Unix Create. Process() Exit. Process() Wait. For. Single. Object() fork() exit() wait() Create. File() Read. File() Write. File() Close. Handle() open() read() write() close() Set. Console. Mode() Read. Console() Write. Console() ioctl() read() write() Get. Current. Process. ID() Set. Timer() Sleep() getpid() alarm() sleep() Create. Pipe() Create. File. Mapping() Map. View. Of. File() pipe() shmget() mmap() Set. File. Security() Initialize. Security. Descriptor() Set. Security. Descriptor. Group() chmod() umask() chown() 9

v Process Control – single-tasking system free memory layout execution flow free memory boot

v Process Control – single-tasking system free memory layout execution flow free memory boot Operating System Concept 8 th edition free memory process free memory shell kernel kernel shell process shell 10

– multi-tasking system memory layout execution flow free memory boot free memory process C

– multi-tasking system memory layout execution flow free memory boot free memory process C process B process A free memory shell kernel kernel shell free memory process C process A process B Operating System Concept 8 th edition 11

v File Management file name type file name Attributes accounting file type information accounting

v File Management file name type file name Attributes accounting file type information accounting Attributes protection codes information create open delete close get file attribute set file attribute protection codes Contents FILE DIRECTORY Operating System Concept 8 th edition Contents read write reposition(lseek) 12

v Device Management Device Abstraction request release physical device Operating System Concept 8 th

v Device Management Device Abstraction request release physical device Operating System Concept 8 th edition … fd = open(“/dev/lp”, …); write(fd, “Greeting!”, …); … Device file contention … fd = open(“/dev/lp”, …); ioctl(fd, CONTROL, …); … 13

v Communication host A host B process A process B process A create …

v Communication host A host B process A process B process A create … … shared region process B attach … Network connect, wait, send, receive, close, … << Message-Passing Model >> Operating System Concept 8 th edition … memory << Shared-Memory Model >> 14

v Information Maintenance – system information – time, date, users, memory, version number, …

v Information Maintenance – system information – time, date, users, memory, version number, … – debugging facility – memory dump, trace, single stepping, … – profiling – statistics for consumption of time and space v Protection – controlling access to resources – setting/getting permissions, allow/deny users, … Operating System Concept 8 th edition 15

2. 5 System Programs Categories Programs File management create, delete, copy, rename, print, dump,

2. 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- compilers, assemblers, debuggers, and language support interpreters Program loading & absolute loaders, relocatable loaders, and linkage execution editors Communications email agents, web browsers, terminal clients Operating System Concept 8 th edition 16

2. 7 Operating-System Structure v Simple Structure application program û solid-combined û vulnerable to

2. 7 Operating-System Structure v Simple Structure application program û solid-combined û vulnerable to malicious programs û adhere to hardware directly resident system program MS-DOS device drivers ROM BIOS device drivers Operating System Concept 8 th edition 17

v Layered Approach Operating System Concept 8 th edition 18

v Layered Approach Operating System Concept 8 th edition 18

v Microkernels << Hybrid Microkernel Model (Mac OS X) >> Operating System Concept 8

v Microkernels << Hybrid Microkernel Model (Mac OS X) >> Operating System Concept 8 th edition 19

v Module Approach << Core kernel & modules (Sun Solaris) >> Operating System Concept

v Module Approach << Core kernel & modules (Sun Solaris) >> Operating System Concept 8 th edition 20

2. 9 Operating-System Debugging v “Debugging” – the activity of finding and fixing errors,

2. 9 Operating-System Debugging v “Debugging” – the activity of finding and fixing errors, or bugs, in a system – a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware thus making it behave as expected (from 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. ” Operating System Concept 8 th edition 21

v Failure Analysis – debugging user-level process code – log file, core dump (a

v Failure 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) v Performance Tuning – seeking to improve performance by removing bottlenecks – add measuring codes – run interactive monitoring tool Operating System Concept 8 th edition 22

% cumulative time seconds 33. 34 0. 02 16. 67 0. 03 16. 67

% cumulative time seconds 33. 34 0. 02 16. 67 0. 03 16. 67 0. 04 16. 67 0. 05 16. 67 0. 06 0. 00 0. 06 self seconds 0. 02 0. 01 0. 00 0. 00 calls 7208 244 8 7 self ms/call 0. 00 0. 04 1. 25 1. 43 236 192 47 45 1 1 1 0. 00 0. 00 total ms/call 0. 00 0. 12 1. 25 1. 43 name open offtime memccpy write mcount 0. 00 tzset 0. 00 tolower 0. 00 strlen 0. 00 strchr 50. 00 main 0. 00 memcpy 10. 11 print 0. 00 profil 50. 00 report << an example of profiling >> Operating System Concept 8 th edition 23

Topas Monitor for host: Sat Oct 24 08: 58: 05 2009 CPU ALL User%

Topas Monitor for host: Sat Oct 24 08: 58: 05 2009 CPU ALL User% 0. 1 Kern% 0. 1 Wait% 0. 0 Network en 1 lo 0 KBPS 0. 4 0. 0 I-Pack 0. 5 0. 0 Disk hdisk 0 hdisk 1 cd 0 Busy% 0. 0 KBPS 0. 0 AX 3 Interval: 2 Idle% 99. 8 O-Pack 1. 0 0. 0 KB-In 0. 0 KB-Out 0. 3 0. 0 – an example of monitoring tools Name dtgreet topas sshd gil java X rpc. lock aixmibd 6 netm syncd xmgc PID 86182 274676 340058 69666 307370 135248 225462 254076 65568 94314 49176 CPU% 0. 1 0. 0 0. 0 TPS KB-Read KB-Writ 0. 0 0. 0 Pg. Sp 1. 3 1. 2 1. 0 0. 9 39. 4 2. 5 1. 2 0. 4 0. 5 0. 4 Owner root root root EVENTS/QUEUES Cswitch 74 Syscall 1484 Reads 1 Writes 2 Forks 0 Execs 0 Runqueue 0. 0 Waitqueue 0. 0 FILE/TTY Readch Writech Rawin Ttyout Igets Namei Dirblk 236 520 0 236 0 0 0 PAGING Faults Steals Pgsp. In Pgsp. Out Page. In Page. Out Sios MEMORY Real, MB % Comp % Noncomp % Client 7936 11. 1 0 0 0 0 PAGING SPACE Size, MB 8192 % Used 0. 0 NFS (calls/sec) % Free 100. 0 Server. V 2 0 Client. V 2 0 Press: Server. V 3 0 "h" for help Client. V 3 0 "q" to quit << an example of monitoring tools >> Operating System Concept 8 th edition 24

v DTrace – dynamic, safe, low-impact debugging (both user/kernel) – a broad & a

v DTrace – 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 function PROBE fire . . . create PROVIDER transfer CONSUMER access kernel data << DTrace Framwork >> Operating System Concept 8 th edition 25

<< trace of “ioctl” system call >> Operating System Concept 8 th edition 26

<< trace of “ioctl” system call >> Operating System Concept 8 th edition 26

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

sched: : : on-cpu uid == 101 { self->ts = timestamp; } sched: : : off-cpu self->ts { @time[execname] = sum(timestamp –self->ts); self->ts = 0; } << an example D code >> Operating System Concept 8 th edition #dtrace –s sched. d dtrace: 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-applet 2 7388447 java 10769137 << DTrace result >> 27