How to protect CPU

we must prevent a user program from getting stuck in an infinite loop or not calling system services, and never returning control to the operating system. This goal is achieved by using timer. 


A timer can be set to interrupt the computer after a specified period. The period may be fixed or variable, A variable timer 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 0, an interrupt occurs. For example, a 10-bit counter with a 1 milisecond clock allows interrupt at intervals from 1 milisecond to 1024 miliseconds, in step of 1 milisecond.Before turning control to the user, the iperating system ensures that the timer is set to interrupt. If the timer intrrupts, control transer automatically to the operating system, which may treat the interrupt as a fatal error or may give the program more time. obviously, instruction that modify the operation of the timer as privileged.



Thus, a timer can be used 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 6 minutes time limite would have its counter initialized to 360. Every second, the timer interrupt and the counter is decremented by 1. As long as the counter is positive, controle is returned to the user programs. When the counter becomes negative, the operating system terminates the program for exceeding the assigned time limit.

Comments

Post a Comment

Popular posts from this blog

Android information

Service of Operating system