sign in
 
   
 
 
 
OPERATING SYSTEM _ INTRODUCTION
Operating-System Operations:
Modern operating systems are interrupt driven. Events are almost always signaled by the occurrence of an interrupt or trap. A trap is a software-generated interrupt caused either by an error or by a specific request from a user program that an operating-system service be performed. For each type of interrupt, separate segments of code in the operating system determine what action should be taken. An interrupt service routine is provided that is responsible for dealing with the interrupt.

Since the operating system and the users share the hardware and software resources of the computer system, we need to make sure that an error in a user program could cause problems only for the one program that was running. A properly designed operating system must ensure that an incorrect (or malicious) program cannot cause other programs to execute incorrectly.
Dual-Mode Operation:
In order to ensure the proper execution of the operating system, we must be able to distinguish between the execution of operating-system code and user-defined code. The approach taken by most computer systems is to provide hardware support that allows us to differentiate among various modes of execution.
There are two separate modes of operations: user mode and kernel mode(also called supervisor mode, system mode, or privileged mode). A bit, called mode bit, is added to the hardware of the computer to indicate the current mode: kernel(0) or user(1). With the mode bit, we are able to distinguish between a task that is executed on behalf of the operating system and one that is executed on behalf of the user.

Transition from user to kernel mode

When the computer system is executing on behalf of a user application, the system is in user mode. However, when a user application requests a service from the operating system via system call, it must transition from user to kernel mode.

At system boot time, the hardware starts in kernel mode. The operating is then loaded and starts user applications in user mode. Whenever a trap or interrupt occurs, the hardware switches from user mode to kernel mode (that is, changes the state of the mode bit to 0). Thus, whenever the operating system gains control of the computer, it is in kernel mode. The system always switches to user mode (by setting the mode bit to 1) before passing control to a user program.

The dual mode of operation provides us with the means for protecting the operating system from erratic users. We accomplish this protection by designating some of the machine instructions that may cause harm as privileged instructions.

The lack of a hardware-supported dual mode can cause serious shortcomings in an operating system. A user program running awry (crooked) can wipe out the operating system by writing over it with data and multiple programs are able to write to a device at the same time, with possibly disastrous results.

Once hardware protection is in place, errors violating modes are detected by the hardware. These errors are normally handled by the Operating System. If a user program attempt either to execute an illegal instruction or to access memory that is not in the user’s address space, then the hardware will trap to the operating system. The trap transfers control through the interrupt vector to the operating system and the program terminate abnormally.
Timer:
We must prevent a user program from getting stuck in an infinite loop or not calling system services and never returning to the operating system. A timer can be used to accomplish this goal. A timer can be set to interrupt the computer after a specified period. The period may be fixed or variable. A variable timer is generally implemented by a fixed-rate clock and a counter. The operating system sets the counter. Every time the clock ticks, the counter is decremented. When the counter reaches zero, an interrupt occurs.

Thus, we can use the timer to prevent a user program from running too long. A simple technique is to initialize a counter with the amount of time that a program is allowed to run. For example, a program with a 7 minute time limit would have its counter initialized to 420. Every second, the timer interrupts and the counter is decremented by 1. When the counter becomes negative, the operating system terminates the program for exceeding the assigned time limit.

Previous Page Previous