1 / 12

Understanding OS Structures for System Programming

Explore system calls, command interpreters, and virtual machines in OS structures. Learn about OS services, function execution, and process management.

ericsantos
Download Presentation

Understanding OS Structures for System Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. 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

  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? Chapter 2: OS Structures

  5. System Call Examples Chapter 2: OS Structures

  6. 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

  7. 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

  8. 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

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

  10. 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

  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 Chapter 2: OS Structures

  12. 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

More Related