DOC PREVIEW
Penn CIS 380 - Processes and Threads

This preview shows page 1-2-3-25-26-27-28-50-51-52 out of 52 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1CSE 380Computer Operating SystemsInstructor: Insup LeeUniversity of PennsylvaniaFall 2003Lecture Note 2: Processes and ThreadsLecture Note 2.1: Processes and System Calls2 Processq Consider a simple disk operating system (like MS-DOS)q User types command like “run foo” at Keyboard (I/O device driver forkeyboard, screen)q Command is parsed by command shellq 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 ==> processcomes 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 context3Multiprogramming/Timesharing Systemsq Goal: to provide interleaved execution of several processes to give anillusion of many simultaneously executing processes.q Computer can be a single-processor or multi-processor machine.q The OS must keep track of the state for each active process and makesure that the correct information is properly installed when a process isgiven control of the CPU.q Many resource allocation issues to consider:ß How to give each process a chance to run?ß How is main memory allocated to processes?ß How are I/O devices scheduled among processes?4Keeping track of processesq For each process, OS maintains a data structure, called theprocess control block (PCB). The PCB provides a way ofaccessing all information relevant to a process:ß This data is either contained directly in the PCB, or else thePCB contains pointers to other system tables.q Processes (PCBs) are manipulated by two maincomponents of the OS in order to achieve the effects ofmultiprogramming:ß Scheduler: determines the order in which processes will gainaccess to the CPU. Efficiency and fair-play are issues here.ß Dispatcher: actually allocates CPU to the process selected bythe scheduler.5Process Contextq 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 recordsq Registers: general registers, PC, SP, PSW, segmentation registersq Other information:ß open files table, status of ongoing I/Oß process status (running, ready, blocked), user id, ...6Process Statesq Possible process statesß Running: executingß Blocked: waiting for I/Oß Ready: waiting to be scheduled7When are processes created?1. System initialization (many daemons forprocessing email, printing, web pages etc.)2. Execution of a process creation system call by arunning process (fork or CreateProcess)3. User request to create a new process (executingnew applications)List of all active processes: ps (on Unix), Ctl-Alt-Del (on Windows)8When are processes terminated?1. Normal exit (voluntary)2. Error exit (voluntary)3. Fatal error (involuntary), due to bugs4. Killed by another process (involuntary)9Process SnapshotStatic dataCode Dynamic dataFree spaceStackCPU(Virtual) MemoryPSW Program Counter Stack Pointer Recall:How is information exchanged betweenA program and its subroutines ?10When does OS get invoked?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 processq System stack can be used to exchange information between OS anduser processesq Recall: Mode bit in PSW is set only when OS is running11Interruptsq An interruption of the normal processing of processor.q Interrupts cause the CPU to suspend its current computation and take upsome new task. Control may be returned to the original task at some timelater.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) arisingduring executionq Interrupts are essentially what drives an OS. We can view the OS as anevent-driven system, where an interrupt is an event.q Bounding interrupt handling latency is important for real-time systems.12Interrupt Handlingq The servicing of an interrupt is known as interrupt handling.q An integer is associated with each type of interrupt. When an interrupt occurs, thecorresponding integer is supplied to the OS usually by the hardware (in a register).q The OS maintains a table, known as the interrupt vector, that associates eachinterrupt's id with the starting address of its service routine.q Example interrupt vector:Interrupt No. Interrupt Handler0 clock1 disk2 tty 3 dev 4 soft 5 other13InterruptsOn 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 interrupts14Typical interrupt handling sequenceq Interrupt initiated by I/O device signaling CPU, by exceptional conditionarising, through execution of special instruction, etc.q CPU suspends execution of current instruction stream and saves thestate 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 isconsulted in order to transfer control to the appropriate interrupthandler.q Interrupt handler performs whatever processing is necessary to dealwith the interrupt.q Previous CPU state is restored (popped) from system stack, and CPUreturns control to interrupted task.15Example: Servicing a Timer Interruptq Timer device is used in CPU scheduling to make sure control isreturned to system every so often (e.g., 1/60 sec.)q Typically, timer has a single register that can be loaded with an integerindicating a particular time delay (# of ticks).q Once loaded, timer counts down and when 0 is reached, an interrupt


View Full Document

Penn CIS 380 - Processes and Threads

Download Processes and Threads
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Processes and Threads and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Processes and Threads 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?