Reviewer: Principles of operating systems

Chapter 3

Traps and Interrupts

Modern OS are known a s being interrupt driven. This simply means that there is no processes or programs to execute, no I/O devices to service and users to whom to respond, an operating system will quietly sit and wait for something to happen.

Trap – is an indicative of an abnormal condition sensed by the CPU, which usually means that an error has occurred.

This error may be in the form of

  1. division by zero
  2. access to an invalid or non – existing memory location
  3. access to a restricted memory location
  4. execution of an undefined code
  5. access to a non – existing peripheral device

In the occurrence of both interrupt and trap the CPU responds by suspending the current. It saves or preserves all the values pertinent to the suspended program such as the value of the program counter, register, memory location of the last line of code executed etc.

After saving the process, it transfers control to an INTERRUPT HANDLER or INTERRUPT SERVICE ROUTINE which determine the appropriate course of action to be taken in response to the interrupt. When the Interrupt Routine has completed it task, the CPU resumes operation to the interrupted/ temporarily suspended task.

Two types of Interrupt

  1. Software Generated – takes the form of traps which execute a special operation known as system call or monitor call.
  2. Hardware Interrupt – take the system bus route to send the signal from the I/O devices to the CPU.

I/O structure input and output operation is implemented using the following techniques.

  1. programmed I/O – the simplest method to implement I/O operation is done through programmed I/O. this method is done by copying the data from the user space to the kernel to avoid a more complex operation should the access be done at the user level. After the data is copied to the kernel the operating systems begin to output the data. For example to an output device like the printer, one character at a time. This loop of fetching from the kernel and sending the character to the output device is the essence of programmed I/O

Polling – process of querying I/O devices to verify the capacity of the device to accept data ready transmission.

Kernel – a part of the Operating system that includes frequently used portions of the software.

  1. Interrupt Driven – enhanced version of the programmed I/O. As stated earlier, I/O devices trigger a hardware interrupt from the I/O device to the CPU. This process of issuing an interrupt “frees the CPU from its busy waiting status and work on another process. As soon as the device is again ready for the next character input the CPU is interrupted or suspends the current process in order to attend to the next character input needed by the device..
  1. Direct Memory Access (DMA) – this is an enhance of the interrupt driven I/O

because it assigns the work of outputting data to a DMA controller instead of generating an interrupt every time a character is outputted

Process Management

Is the fundamental task of an operating system. Most authors also believe that the central concept in any modern Operating System is undoubtedly the concept of Process.

Process – a program in execution (active entity)

Program – set of instructions. (passive entity)

Process State Models

  1. two state process model

“ as a process execute, it changes its state. The current activity of a process party is a state. A process actually a cycle of CPU execution (CPU burst) and (I/O burst). Usually there is a large number of short CPU burst or there is a small number of long CPU bursts. An I/O bound program would typically have many very short CPU burst. A CPU – bound program might have a few very long CPU burst.

A process generally includes the

A. process stack – containing temporary data (such as sub routine parameters, return addresses and local variables

B. data section – containing global variables.

  1. Three State process Model
    1. running – a process that is currently using the CPU
    2. ready – runnable but is on hold until CPU is available
    3. blocked – unable to run until an external event occurs.
  1. Five State process Model
    1. New – the process is being created
    2. Running – The CPU is executing its instruction
    3. Waiting – the process is waiting for some event to occur
    4. Ready – the process is waiting for the OS to assign a processor to it
    5. Terminated – the process has finished execution

Process Creation and Termination

Process creation can be summarized into four principal events

  1. System Utilization – when the computer is booted up, processes are created in the computer system like the loading process..

Foreground process – interact with human users through the system interface

Background process –executes without the users knowledge. Like a process to accept email. Such process is dormant until it is triggered by the coming of an email

  1. Process Spawning by an executing process – when a process is executing it may

Issue a process creation system call which will create another process as requested. This is a classic example of a help me process wherein the purpose of the process to be created is to help the summoning process.

  1. User Request to create new process – this process creation event originates in an Interactive or time sharing system. A user creates a process using the input devices of the computer system.
  1. Initiation of a batch job – this fourth event is found on batch systems of large

mainframes. Since jobs are submitted in bulks, as the soon as the OS sees that the required resources for the next job in the input queue is available it then creates

another process to execute the job.

Process Termination according to stallings are terminated by any of the following events

  1. Normal Completion – a process issues a system call that it has finished its work. An example is a compiler which has finished compiling a particular program
  2. Time limit exceeded – this means that a process exceeds its time limit. Like in the email process, if there are no inputs or interaction from the user for some amount of time then the process is deactivated to resume or reactivate the terminated process would require a login
  3. Memory unavailable – there is insufficient memory than what is being required by a process
  4. bound violation –the process tries to access a restricted memory location.
  5. protection error – the process attempts to access a restricted resource / file or uses it in an improper fashion
  6. arithmetic error – the process performs illegal computation such as division by zero
  7. time over run – occurs when a process has to wait more than the maximum time for an event to take place.
  8. I/O failure – occurs when an error is encountered in an I/O device.
  9. Invalid Instruction – the process tries to execute a nonexistent instruction
  10. privileged instruction – occurs when the process attempts to execute an instruction reserved for the OS alone.
  11. data mis-use – happens when data is of the wrong type or not initialized.
  12. operator or Os intervention – OS terminates a process if a deadlock occurs
  13. parent termination – when a parent terminates its offspring are tagged along
  14. parent request – a parent process is authorized to terminate any of its offspring process.

Process Implementation

Each process is represented in the operating system by a process control block(PCB). A PCB is a data block record containing many pieces of the information associate with a specific process including

  1. process state
  2. program counter – indicates the address of the next instruction to be executed for this process
  3. CPU registers – includes accumulators, index, registers, stack pointers , and general purpose registers
  4. CPU Scheduling Information – this information includes a process priority, pointers to scheduling queues and any other scheduling parameters
  5. memory management information – this information includes limit registers or page tables
  6. accounting information – this includes the amount of the cpu and real time used, time limits, account numbers, job or process numbers and so on.

7 I/O status information – this information includes outstanding I/O request , I/O devices allocated to this process, a list of open files, and so on.

Chapter 4

CPU scheduling

CPU schedulers – whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue for execution. CPU scheduling may take place under the following four circumstances

  1. when a process switches from running state to the waiting state
  2. when a process switches from the running state to the ready state
  3. when a process switches from the waiting state to the ready state
  4. when a process switches from the ready state to the running state

CPU scheduling algorithms – different CPU algorithms have different properties and may favour one class of processes over another. The characteristics used for comparison can make substantial difference in the determination of the best algorithm.

  1. CPU utilization – this measures how busy is the CPU
  2. throughput – this is a measure of work (number of processes competed per time unit
  3. turnaround time – this measure how long it takes to execute a process. Turnaround time is the interval from the time of submission to the time of completion. It is the sum of the periods spent waiting to get into memory. Waiting in the ready queue , executing in the CPU and doing I/O.
  4. waiting time – total amount of time a process spends waiting in the ready queue
  5. response time – the time from the submission of a request until the system makes the first response. It is the amount of time it takes to start responding but not the time it takes to output that response..