Unformatted text preview:

CSE 380 Computer Operating SystemsProcessMultiprogramming/Timesharing SystemsKeeping track of processesProcess ContextProcess StatesWhen are processes created?When are processes terminated?Process SnapshotWhen does OS get invoked?InterruptsInterrupt HandlingSlide 13Typical interrupt handling sequenceExample: Servicing a Timer InterruptExample: Servicing a Disk InterruptSystem CallsSlide 18Steps in System CallSteps in System Call (cont)Slide 21Creating processes in UNIXProcess HierarchiesInitializationUNIX Process ControlThe Fork System CallSnapshots after fork()Example using forkSample QuestionSpawning Applicationsexec System CallParent-Child SynchronizationProcess TerminationHow shell executes a commandSlide 35Introduction to ThreadsWhen are threads useful?Challenges in single-threaded solnSolution with ThreadsParallel Algorithms: Eg. mergesortBenefits of Threads: SummaryThreads ModelProcesses and ThreadsThread CreationSample CodeEnsuring main thread waits…Thread TerminationImplementing Threads in User SpaceUser-Level ThreadsImplementing Threads in the KernelKernel-supported ThreadsUser-level vs. Kernel-supported Threads1CSE 380Computer Operating SystemsInstructor: Insup LeeUniversity of PennsylvaniaFall 2003Lecture Note 2: Processes and ThreadsLecture Note 2.1: Processes and System Calls2 Process Consider a simple disk operating system (like MS-DOS)User types command like “run foo” at Keyboard (I/O device driver for keyboard, screen)Command is parsed by command shellExecutable program file (load module) “foo” is located on disk (file system, I/O device driver for disk)Contents are loaded into memory and control transferred ==> process comes alive! (disk device driver, relocating loader, memory management)During execution, process may call OS to perform I/O: console, disk, printer, etc. (system call interface, I/O device drivers)When process terminates, memory is reclaimed (memory management)A process is a program in execution with associated data and execution context3Multiprogramming/Timesharing SystemsGoal: to provide interleaved execution of several processes to give an illusion of many simultaneously executing processes.Computer can be a single-processor or multi-processor machine.The OS must keep track of the state for each active process and make sure that the correct information is properly installed when a process is given control of the CPU.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 processesFor each process, OS maintains a data structure, called the process control block (PCB). The PCB provides a way of accessing all information relevant to a process:This data is either contained directly in the PCB, or else the PCB contains pointers to other system tables. Processes (PCBs) are manipulated by two main components of the OS in order to achieve the effects of multiprogramming:Scheduler: determines the order in which processes will gain access to the CPU. Efficiency and fair-play are issues here.Dispatcher: actually allocates CPU to the process selected by the scheduler.5Process Context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.)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Registers: general registers, PC, SP, PSW, segmentation registersOther information:open files table, status of ongoing I/Oprocess status (running, ready, blocked), user id, ...6Process States Possible process statesRunning: executingBlocked: waiting for I/OReady: waiting to be scheduled7When are processes created?1. System initialization (many daemons for processing email, printing, web pages etc.)2. Execution of a process creation system call by a running process (fork or CreateProcess)3. User request to create a new process (executing new 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?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System stack can be used to exchange information between OS and user processesRecall: Mode bit in PSW is set only when OS is running11InterruptsAn interruption of the normal processing of processor.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.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Interrupts are essentially what drives an OS. We can view the OS as an event-driven system, where an interrupt is an event.Bounding interrupt handling latency is important for real-time systems.12Interrupt HandlingThe servicing of an interrupt is known as interrupt handling.An integer is associated with each type of interrupt. When an interrupt occurs, the corresponding integer is supplied to the OS usually by the hardware (in a register).The OS maintains a table, known as the interrupt vector, that associates each interrupt's id with the starting address of its service routine.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


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?