












































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













































Instructor: Insup Lee University of Pennsylvania Fall 2003 Lecture Note 2: Processes and Threads Lecture Note 2.1: Processes and System Calls
q Consider a simple disk operating system (like MS-DOS) q User types command like “run foo” at Keyboard (I/O device driver for keyboard, screen) q Command is parsed by command shell q Executable program file (load module) “foo” is located on disk (file system, I/O device driver for disk) q Contents are loaded into memory and control transferred ==> process comes alive! (disk device driver, relocating loader, memory management) q During execution, process may call OS to perform I/O: console, disk, printer, etc. (system call interface, I/O device drivers) q When process terminates, memory is reclaimed (memory management) A process is a program in execution with associated data and execution context
q The context (or image) of a process can be described by ß contents of main memory ß contents of CPU registers ß other info (open files, I/O in progress, etc.) q Main memory -- three logically distinct regions of memory: ß text region: contains executable code (typically read-only) ß data region: storage area for dynamically allocated data structure, e.g., lists, trees (typically heap data structure) ß stack region: run-time stack of activation records q Registers: general registers, PC, SP, PSW, segmentation registers q Other information: ß open files table, status of ongoing I/O ß process status (running, ready, blocked), user id, ...
List of all active processes: ps (on Unix), Ctl-Alt-Del (on Windows)
q Operating system gets control in two ways ß A user process calls OS by a system call (e.g. executes TRAP) ß An interrupt aborts the current user process q System stack can be used to exchange information between OS and user processes q Recall: Mode bit in PSW is set only when OS is running
q An interruption of the normal processing of processor. q Interrupts cause the CPU to suspend its current computation and take up some new task. Control may be returned to the original task at some time later. q Reasons for interrupts and/or traps: ß control of asynchronous I/O devices ß CPU scheduling ß exceptional conditions (e.g., div. by zero, page fault, illegal instruction) arising during execution q Interrupts are essentially what drives an OS. We can view the OS as an event-driven system, where an interrupt is an event. q Bounding interrupt handling latency is important for real-time systems.
On Intel Pentium, hardware interrupts are numbered 0 to 255 ß 0: divide error ß 1: debug exception ß 2: null interrupt ß 6: invalid opcode ß 12: stack fault ß 14: page fault ß 16: floating-point error ß 19-31: Intel reserved (not available?) ß 32-255: maskable interrupts (device controllers, software traps) Issue: can CPU be interrupted while an OS interrupt handler is executing? Maskable interrupts can be disabled, plus there is a priority among interrupts
14
q Interrupt initiated by I/O device signaling CPU, by exceptional condition arising, through execution of special instruction, etc. q CPU suspends execution of current instruction stream and saves the state of the interrupted process (on system stack). q State typically refers to contents of registers: PC, PSW, SP, general- purpose registers. q The cause of the interrupt is determined and the interrupt vector is consulted in order to transfer control to the appropriate interrupt handler. q Interrupt handler performs whatever processing is necessary to deal with the interrupt. q Previous CPU state is restored (popped) from system stack, and CPU returns control to interrupted task.
q When disk controller completes previous transfer, it generates an interrupt. q Interrupt handler changes the state of a process that was waiting for just-completed transfer from wait-state to ready-state. q It also examines queue of I/O requests to obtain next request. q I/O is initiated on next request. q CPU scheduler called. q Control returned to user mode.
q Provide "direct access" to operating system services (e.g., file system, I/O routines, memory allocate & free routines) by user programs. q System calls are special, and in fact, are treated like interrupts. q Programs that make system calls were traditionally called "system programs" and were traditionally implemented in assembly language ß Win32 API in Windows q Each system call had a particular number. Instruction set has a special instruction for making system calls: SVC (IBM 360/370) trap (PDP 11) tw (PowerPC) - trap word tcc (Sparc) break (MIPS)