Course Name: Introduction to Operating Systems
Course Code: ICT-553
Credit Hours: 3(2-1)
Topic: Operating System Operations
Level: BS
lecture#2
Department of Information Technology , Government College Women University Faisalabad
Objectives
• The following topics will be covered in this
lecture:
Operating System Operations
Dual mode operations
System call
Timer
1. Operating System Operations
• As mentioned earlier, modern operating
system are interrupt driven.
• If there are no processes to execute, no I/0
devices to service, and no users to whom to
respond, an operating system will sit quietly
waiting for something to happen.
• Events are almost always signaled by the
occurrence of an interrupt or a trap.
[Link] System Operations (Conti…)
• A trap is a software generated interrupt caused by an
error (for example division by zero or invalid memory
access)or by a specific request from a user program that
an operating-system service be performed.
• The interrupt-driven nature of an operating system
defines that system's general structure.
• 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.
Operating System Operations (Conti…)
• 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 running.
• With sharing, many processes could be adversely affected by
a bug in one program.
• For example, if a process gets stuck in an infinite loop, this
loop could prevent the correct operation of many other
processes. More subtle errors can occur in a
multiprogramming system, where one erroneous program
might modify another program, the data of another program,
or even the operating system itself.
1.1 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.
1.1 Dual Mode Operation (Conti…)
• There are two separate modes of operation:
User mode
Kernel mode(supervisor mode, privileged mode or
system 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).
1.1 Dual Mode Operation (Conti…)
• With the mode bit we are able to distinguish
between a task 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), it must transition from user to kernel mode
to fulfill the request, this is shown in Figure.
Figure : Transition from user to kernel mode
1.1 Dual Mode Operation (Conti…)
• At system boot time, the hardware starts in kernel
mode.
• The operating system 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.
1.1 Dual Mode Operation (Conti…)
• The dual mode of operation provides us with
the means for protecting the operating system
from errant users-and errant users from one
another.
• The instruction to switch to kernel mode is an
example of a privileged instruction. Some
other examples include I/0 controt timer
management and interrupt management.
System calls
• A system call is invoked in a variety of ways, depending
on the functionality provided by the underlying
processor. In all forms, it is the method used by a
process to request action by the operating system.
• A system call usually takes the form of a trap to a
specific location in the interrupt vector.
• This trap can be executed by a generic trap instruction,
although some systems (such as the MIPS R2000
family) have a specific syscall instruction.
System Call (Conti…)
• When a system call is executed, it is treated by the
hardware as the software interrupt.
• The control passes through the interrupt vector to a
service routine in the operating system/ and the
mode bit is set to kernel mode.
• The system call service routine is a part of the
operating system. The-kernel examines the
interrupting instruction to determine what system
call has occurred; a parameter indicates what type of
service the user program is requesting.
System Call (Conti…)
• Most contemporary operating systems such as
Microsoft Vista and Windows XP, as well as
Unix, Linux, and Solaris take advantage of this
dual-mode feature and provide greater
protection for the operating system.
Timer
• We cannot allow a user program to get stuck
in a 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 specific period.
• The time period must be fixed (for example
1/60 seconds).
Timer (Conti….)
• 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.
For instance, a 10-bit counter with a 1 millisecond
clock allows interrupts at intervals from 1
millisecond to 1,024 milliseconds, in steps of 1
millisecond.