University of Pennsylvania 9/12/00CSE 3801 Processes, Interrupts, and System Calls CSE 380 Lecture Note 2 Insup Lee.

Slides:



Advertisements
Similar presentations
Computer-System Structures Er.Harsimran Singh
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Chapter 3 Process Description and Control
Lecture 11: Operating System Services. What is an Operating System? An operating system is an event driven program which acts as an interface between.
6/9/2015B.Ramamurthy1 Process Description and Control B.Ramamurthy.
Process Description and Control
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Process Description and Control Chapter 3. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
OS2-1 Chapter 2 Computer System Structures. OS2-2 Outlines Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
1 Lecture 2: Review of Computer Organization Operating System Spring 2007.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
CSCE 351: Operating System Kernels
Chapter 7 Interupts DMA Channels Context Switching.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
Exceptions, Interrupts & Traps
Copyright Arshi Khan1 System Programming Instructor Arshi Khan.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
System Calls 1.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
Chapter 1. Introduction What is an Operating System? Mainframe Systems
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Chapter 3 Process Description and Control
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Operating Systems 1 K. Salah Module 2.0: Processes Process Concept Trace of Processes Process Context Context Switching Threads –ULT –KLT.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Lecture 1: Review of Computer Organization
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Processes and threads.
Process concept.
Protection of System Resources
Day 08 Processes.
Day 09 Processes.
Structure of Processes
Computer System Overview
Computer-System Architecture
Module 2: Computer-System Structures
Process & its States Lecture 5.
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Module 2: Computer-System Structures
Process Description and Control
Process Description and Control
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Process Description and Control
Module 2: Computer-System Structures
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Module 2: Computer-System Structures
Presentation transcript:

University of Pennsylvania 9/12/00CSE 3801 Processes, Interrupts, and System Calls CSE 380 Lecture Note 2 Insup Lee

University of Pennsylvania 9/12/00CSE 3802 Process Main purpose of an operating system is to facilitate the execution of user application programs. Useful and Important Concept: Process = program in execution A process is not the same as a program. Program is a passive entity, whereas process is active. Process consists of an executable program, associated data, and execution context. Modern (multiprogramming) operating systems are structured around the concept of a process. Multiprogramming OS supports execution of many concurrent processes. OS issues tend to revolve around management of processes: –How are processes created/destroyed? –How to manage resource requirements of a process during its execution: cpu time, memory, I/O, communication,... ? –How to avoid interference between processes? –How to achieve cooperation between processes?

University of Pennsylvania 9/12/00CSE 3803 Program Creation Program (say, C program) is edited It is compiled into assembly language, which may consist of several modules. Assembly language modules are assembled into machine code. External references (i.e., to procedures and data in another module) are resolved. This is called linking, which creates a load module. Load module is stored as a file in file system and may be executed at a later time by loading into memory to be executed.

University of Pennsylvania 9/12/00CSE 3804 Process creation and termination 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! (device driver for disk, 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)

University of Pennsylvania 9/12/00CSE 3805 Process 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 CPU 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,...

University of Pennsylvania 9/12/00CSE 3806 Multiprogramming/Timesharing Systems They provide interleaved execution of several processes to give an illusion of many simultaneously executing processes. Computers 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?

University of Pennsylvania 9/12/00CSE 3807 Interrupts (fundamental concept) An interruption of the normal processing of processor. Interrupts are a mechanism for causing 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 (or traps): –control of asynchronous I/O devices –CPU scheduling –exceptional conditions (e.g., div. by zero, page fault, illegal instruction) arising during execution –user process requests for OS services Interrupts are essentially what drives an OS. We can view the OS as an event-driven system, where an interrupt is an event. By their very nature, interrupts need to be serviced carefully and quickly by the OS. Bounding interrupt handling latency is important for real-time systems.

University of Pennsylvania 9/12/00CSE 3808 Interrupt 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 Handler 0clock 1disk 2tty 3dev 4soft 5other

University of Pennsylvania 9/12/00CSE 3809 Typical interrupt handling sequence  Interrupt initiated by I/O device signaling CPU, by exceptional condition arising, through execution of special instruction, etc.  CPU suspends execution of current instruction stream and saves the state of the interrupted process (on hardware stack).  State typically refers to contents of registers: PC, PSW, SP, general-purpose registers.  The cause of the interrupt is determined (and the unit no. of the interrupt, if applicable) and the interrupt vector is consulted in order to transfer control to the appropriate interrupt handler.  Interrupt handler performs whatever processing is necessary to deal with the interrupt.  Previous CPU state is restored (popped) from system stack, and CPU returns control to interrupted task.

University of Pennsylvania 9/12/00CSE Example: Servicing a Timer Interrupt Timer device is used in CPU scheduling to make sure control is returned to system every so often (e.g., 1/60 sec.) Typically, timer has a single register that can be loaded with an integer indicating a particular time delay (# of ticks). Once loaded, timer counts down and when 0 is reached, an interrupt is generated. Interrupt handler might do the following: –update time-of-day information –signal any processes that are "asleep" and awaiting this alarm –call the CPU scheduler Control returns to user mode, possibly to a different process than the one executing when the interrupt occurred.

University of Pennsylvania 9/12/00CSE Example: Servicing a Disk Interrupt When disk controller completes previous transfer, it generates an interrupt. Interrupt handler changes the state of a process that was waiting for just-completed transfer from wait-state to ready-state. It also examines queue of I/O requests to obtain next request. I/O is initiated on next request. CPU scheduler called. Control returned to user mode.

University of Pennsylvania 9/12/00CSE Priority Interrupts Some fast devices (e.g. disk, timer) must be serviced with stringent real-time constraints. Other, slower devices (e.g. TTY) need not be serviced as quickly. Failure to service fast devices soon enough may result in lost interrupts. The priority interrupt mechanism allows the interrupt handler of a slow device to be interrupted by a faster device, while blocking out interrupts from slower devices during execution of interrupt handler of a fast device. Machine Errors ClockHigher priority Disk Network Devices TerminalsLower Priority Software interrupts Typical Interrupt Levels

University of Pennsylvania 9/12/00CSE Priority Interrupt Mechanism How it works: –CPU status register (PSW) contains bits specifying processor priority (or execution) level. –Each device has an associated device priority level. A device may cause an interrupt only when its priority level is higher than the current processor priority level. –Interrupt handler for a device executes at processor priority equal to device priority. –Effect: An interrupt handler can only be interrupted by devices of higher priority.

University of Pennsylvania 9/12/00CSE System Calls Provide "direct access" to operating system services (e.g., file system, I/O routines, memory allocate & free routines) by user programs. As we will see, system calls are special, and in fact, are treated as a special case of interrupts. Programs that make system calls were traditionally called "system programs" and were traditionally implemented in assembly language. 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)

University of Pennsylvania 9/12/00CSE System Calls (cont.) Now, system calls can be made from high-level languages, such as C and Modula-2 (to a degree). Makes life easier: SVC 15 vs. Read (file-d, buffer, n-bytes) System calls execute instructions that control the resources of the computer system, e.g., I/O instructions for devices. We want such privileged instructions to be executed only by a system routine, under the control of the OS!

University of Pennsylvania 9/12/00CSE User vs. System Mode Special mode-bit set in PSW register: mode-bit = 0 => user program executing mode-bit = 1 => system routine executing Privileged instructions possible only when mode-bit = 1! System (or kernel) memory User Program (text) “trap” to O.S. case i-call trap n l : n : code for read

University of Pennsylvania 9/12/00CSE System Call Scenario User program executing (mode-bit = 0) User makes a system call  hardware sets mode-bit to 1  system saves state of user process  branch to case statement in system code  branch to code for system routine based on system call number  copy parameters from user stack to U area  execute system call (using privileged instructions)  restore state of user program  hardware resets mode-bit  return to user process

University of Pennsylvania 9/12/00CSE System Call Scenario (cont.) User program File system memory Operating System User program is confined! I/O devices