120 likes | 133 Views
Explore system calls, command interpreters, and virtual machines in OS structures. Learn about OS services, function execution, and process management.
E N D
Chapter 2: OS StructuresCSS503 Systems Programming Prof. Munehiro Fukuda Computing & Software Systems University of Washington Bothell Chapter 2: OS Structures
A View of OS Services 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; } Chapter 2: OS Structures
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? Chapter 2: OS Structures
System Call Examples 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 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 Chapter 2: OS Structures
MS-DOS (a) At system startup (b) running a program Command Interpreter (Cont’d) • Unix Shell (interpreter) as one of user processes Chapter 2: OS Structures
Bourne shell command interpreter Mac OS X GUI Command Interpreter (Cont’d) 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 (2)pipe cin cout Chapter 2: OS Structures
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 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? Chapter 2: OS Structures