1 Operating System Overview
1 Operating System Overview
• Control program is concerned with the operation and control of I/O devices.
• Since, main memory is too small to accommodate all jobs, the jobs are kept
initially on the disk in the job pool.
• This pool consists of all processes residing on disk awaiting allocation of
main memory.
• The set of jobs in memory can be a subset of the jobs kept in the job pool.
• The operating system picks and begins to execute one of the jobs in memory.
• Finally, the job may have to wait for some task, such as an I/O operation, to
complete.
• In a non-multiprogrammed system, the CPU would sit idle.
• In a multiprogrammed system, the operating system simply switches to, and
executes, another job.
• When that job needs to wait, the CPU switches to another job, and so on.
• Finally, the first job finishes waiting and gets the CPU back. As long as at
least one job needs to execute, the CPU is never idle.
• This idea is common in other life situations.
• A lawyer does not work for only one client at a time.
11
• At the very least, we need two separate modes of operation: user mode and
kernel mode (also called supervisor mode, system mode, or privileged
mode).
• A bit, called the 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 can distinguish between a task that is executed on
behalf of the operating system and one that is executed on behalf of the user.
• 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 a system call), the system must transition from user to kernel
mode to fulfill the request.
• This is shown in Figure 1.10.
1.5.2 Timer
• We must ensure that the operating system maintains control over the CPU.
• We cannot allow a user program to get stuck in an infinite loop or to fail to
call system services and never return control to the operating system. To
accomplish this goal, we can use a timer.
• A timer can be set to interrupt the computer after a specified period.
• The period may be fixed (for example, 1/60 second) or variable (for
example, from 1 millisecond to 1 second).
• 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 0, an interrupt occurs.
• Before turning over control to the user, the operating system ensures that the
timer is set to interrupt.
• If the timer interrupts, control transfers automatically to the operating
system, which may treat the interrupt as a fatal error or may give the
program more time.
• Clearly, instructions that modify the content of the timer are privileged.
• 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.
• A program with a 7-minute time limit, for example, would have its counter
initialized to 420.
• Every second, the timer interrupts, and the counter is decremented by 1.
• As long as the counter is positive, control is returned to the user program.
• When the counter becomes negative, the operating system terminates the
program for exceeding the assigned time limit.