Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2: OS Structures CSS503 Systems Programming

Similar presentations


Presentation on theme: "Chapter 2: OS Structures CSS503 Systems Programming"— Presentation transcript:

1 Chapter 2: OS Structures CSS503 Systems Programming
Prof. Munehiro Fukuda Computing & Software Systems University of Washington Bothell CSS503 Chapter 2: OS Structures

2 Chapter 2: OS Structures
A View of OS Services CSS503 Chapter 2: OS Structures

3 Chapter 2: OS Structures
System Calls Software interface to OS A System function is compiled into “trap args” “Trap” changes CPU mode from user to kernel. CPU checks the OS branch table. Jumps to the code pointed to by the table entry. Work on the requested call. IRET. user application open( ) INT or TRAP argument user mode system call interface kernel mode branch table trusted code open( ) { IRET; } CSS503 Chapter 2: OS Structures

4 System Calls - Questions
In the previous chart, Why can’t a user program technically execute the OS-trusted code? Which process executes the OS-trusted code? The same process? If so, can’t the same stack mix up the user and the kernel-local variables? CSS503 Chapter 2: OS Structures

5 Chapter 2: OS Structures
System Call Examples Windows Unix Process Control CreateProcess( ) fork( ) ExitProcess( ) exit( ) WaitForSingleObject( ) wait( ) File Manipulation CreateFile( ) open( ) ReadFile( ) read( ) WriteFile( ) write( ) CloseHandle( ) close( ) Device Manipulation SetCosoleMode( ) ioctl( ) ReadConsole( ) WriteConsole( ) Information Maintenance GetCurrentProcessID( ) getpid( ) SetTimer( ) aAlarm( ) Sleep( ) sSleep( ) Communication CreatePipe( ) pipe( ) CreateFileMapping( ) shmget( ) MapViewOfFile( ) mmap( ) Protection SetFileSecurity( ) cChmod( ) InitializeSecurityDescriptor( ) umask( ) SetSecurityDescriptorGroup( ) chown( ) CSS503 Chapter 2: OS Structures

6 Chapter 2: OS Structures
Standard C Library C program invoking fopen(), fgets(), and printf(), which call open(), read() and write() system calls #include <stdio.h> Int main( ) { FILE *f = fopen( “myFile”, “r” ); char buf[10]; fgets( buf, sizeof( buf ), f ); printf( “%s\n”, buf ); return 0; } user mode Standard C Library System Call Interface: sd = open( “myFile”, O_RDONLY ), read( fd, buf, sizeof( buf ), write( 1, buf, sizeof( buf ) ) kernel mode CSS503 Chapter 2: OS Structures

7 Chapter 2: OS Structures
Command Interpreter The program that reads and interprets control statements command-line interpreter (in DOS) shell (in UNIX) Mouse-based window and menu system (in Macintosh, Windows, and Linux) What control statements can you pass the command interpreter? Program execution: a.out, g++, emacs Process management: ps, kill, sleep, top, nice, pstack I/O operations: lpr, clear, lprm, mt File-system manipulation: ls, mkdir, mv, rm, chmod, [u]mount Communication: write, ping, mesg CSS503 Chapter 2: OS Structures

8 Command Interpreter (Cont’d)
MS-DOS (a) At system startup (b) running a program Unix Shell (interpreter) as one of user processes CSS503 Chapter 2: OS Structures

9 Command Interpreter (Cont’d)
Bourne shell command interpreter Mac OS X GUI CSS503 Chapter 2: OS Structures

10 Chapter 2: OS Structures
Unix Shell fork, exec, and dup are System calls telnetd goodall login: mfukuda fork, exec and wait login Shell goodall[1]% (you got to type) (1)fork & wait (5)exit Shell wc Shell who (3)fork goodall[1]% who | wc -l (4)exec (4)exec cin (2)pipe cout CSS503 Chapter 2: OS Structures

11 Virtual Machine Conventional OS Binary Translation Para Virtualization
Intel VM Extension Ring 3 Ring 3 Process Process Process Process Process Process Process Process Process Process Process Process Process Process Process Process Ring 1 System calls System calls System calls System calls Ring 1 Guest OS Guest OS Guest OS Guest OS Priveleged instr. Interrupts Function calls Ring 0 Interrupts Ring 0 OS Virtual Machine Monitor (e.g. VMWare) Hypervisor (e.g. Xen) Guest OS Guest OS Priveleged instr. VM Exit VM Return VMX Root Priveleged instr. Interrupts VMM Priveleged instr. Interrupts Priveleged instr. Interrupts Priveleged instr. Interrupts Physical Layer Hardware Hardware Hardware Hardware Physical Layer CSS503 Chapter 2: OS Structures

12 Chapter 2: OS Structures
Discussion Solve Text Exercises: 2.7 (System Programs) 2.16 (System Calls) Discuss about: In what particular situation have your program received a segmentation fault? To read data from a file, why do we need to call open and close the file? In other words, why doesn’t OS allow read( filename, data, size )? If your C++ program terminates upon an exception, it may not print out a cout statement that must have been executed before the exception. Why? CSS503 Chapter 2: OS Structures


Download ppt "Chapter 2: OS Structures CSS503 Systems Programming"

Similar presentations


Ads by Google