OPERATING SYSTEMS
INTRODUCTION
Objectives of OS
• An operating system can be thought of as having three objectives or
as performing three functions.
• Convenience - An operating system makes a computer more convenient to
use.
• Efficiency - An operating system allows the computer system resources to be
used in an efficient manner.
• Ability to evolve - An operating system should be constructed in such a way as
to permit the effective development, testing and introduction of new system
functions without interfering with current services provided.
Uni-programming
• Uni-programming is a term used for those computers which can have only a
single task/job in the main memory at a time.
• Any job/task which has to be executed/run by the CPU must be present in the
main memory and if a computer can have only a single task in the main memory
at a time then it is known as Uni-Programming.
Multi-Programming
• In multi-programming more than one process
can reside in the main memory at a time.
• Thus, when process P1 goes for I/O operation
the CPU is not kept waiting and is allocated to
some another process (lets say P2).
• This keeps the CPU busy at all times.
Multi-tasking
• Multitasking is the process of performing multiple tasks at the same time.
• For example, multiple applications execute in a computer simultaneously.
• Browser, word application, calculator, etc. can execute at the same time.
Multi-tasking
• Even though most modern computers support multitasking, the system can
execute a specific number of tasks at a time.
• It is because when there are multiple tasks, each task requires more resources.
• Thus, this can cause a decrease in system performance.
• Therefore, an adequate number of tasks executes at a time.
• Overall, multitasking helps to improve the productivity of the system.
• Multi-tasking system uses multi-programming.
Time-sharing
• Time sharing is a method that allows multiple users to share resources at the
same time.
• Multiple users in various locations can use a specific computer system at a time.
• Several terminals are attached to a single dedicated server with its own process.
• Therefore, the processor executes multiple user programs simultaneously.
• In other words, the processor time is shared between multiple users at a time.
• The processor allows each user program to execute for a small time quantum.
• Moreover, time sharing systems use multiprogramming and multitasking.
Time-sharing vs Multi-tasking
• Time sharing is the sharing of a computing resource among many users by means
of multiprogramming and multitasking at the same time whereas multitasking is
the concurrent execution of multiple tasks or processes over a certain period of
time.
Multi-processing
• In a uni-processor system, only one process executes at a time.
• Multiprocessing is the use of two or more CPUs (processors) within a single
Computer system.
• The term also refers to the ability of a system to support more than one
processor within a single computer system.
• Now since there are multiple processors available, multiple processes can be
executed at a time.
• These multi processors share the computer bus, sometimes the clock, memory
and peripheral devices also.
Multi-processing
• Multiprocessing refers to the hardware (i.e., the CPU units) rather than the
software (i.e., running processes).
• If the underlying hardware provides more than one processor then that is
multiprocessing.
• It is the ability of the system to leverage multiple processors’ computing power.
Multi-threading
• A thread is a basic unit of CPU utilization.
• Multi threading is an execution model that allows a single process to have
multiple code segments (i.e., threads) running concurrently within the “context”
of that process.
• e.g. VLC media player, where one thread is used for opening the VLC media
player, one thread for playing a particular song and another thread for adding
new songs to the playlist.
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.
• 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).
• Increasingly CPUs support multi-mode operations
• i.e. virtual machine manager (VMM) mode for guest VMs
Dual mode operation
• 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.
Transition from user to kernel mode
Dual mode operation
• 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.
Dual mode operation
• The dual mode of operation provides us with the means for protecting the
operating system from errant users—and errant users from one another.
• We accomplish this protection by designating some of the machine instructions
that may cause harm as privileged instructions.
• The hardware allows privileged instructions to be executed only in kernel mode.
• If an attempt is made to execute a privileged instruction in user mode, the
hardware does not execute the instruction but rather treats it as illegal and traps
it to the operating system.
A trap (or an exception) is a software-generated interrupt caused either 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.
System Calls
• System calls provide the means for a user program to ask the operating system to
perform tasks reserved for the operating system on the user program’s behalf.
• A system call is invoked in a variety of ways, depending on the functionality
provided by the underlying processor, like a trap to a specific location in the
interrupt vector.
• In all forms, it is the method used by a process to request action by the operating
system.
• The system-call service routine is a part of the operating system.
• These calls are generally available as functions written in C and C++, although
certain low-level tasks (for example, tasks where hardware must be accessed
directly) may have to be written using assembly-language instructions.
System Calls
• When a system call is executed, it is typically treated by the hardware as a
software interrupt.
• Control passes through the interrupt vector to a service routine in the operating
system, and the mode bit is set to kernel mode.
• 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.
• Additional information needed for the request may be passed in registers, on the
stack, or in memory (with pointers to the memory locations passed in registers).
• The kernel verifies that the parameters are correct and legal, executes the
request, and returns control to the instruction following the system call.
System Calls
The handling of a user application invoking the open() system call.
Types of System Calls
• System calls can be grouped roughly into six major categories:
• process control
• file management
• device management
• information maintenance
• communications
• protection
Types of System Calls
Some examples of System Calls
C Library
API for System Calls
• Typically, application developers design programs according to an application
programming interface (API).
• The API specifies a set of functions that are available to an application
programmer, including the parameters that are passed to each function and the
return values the programmer can expect.
• A programmer accesses an API via a library of code provided by the operating
system and is called libc (in case of Linux and Unix).
• Why would an application programmer prefer programming according to an API
rather than invoking actual system calls?
• One benefit concerns program portability.
• An application programmer designing a program using an API can expect her program to
compile and run on any system that supports the same API
System Boot
• The procedure of starting a computer by loading the kernel is known as booting
the system.
• On most computer systems, a small piece of code known as the bootstrap
program or bootstrap loader locates the kernel, loads it into main memory, and
starts its execution.
• When a CPU is powered up or rebooted—the instruction register is loaded with a
predefined memory location, and execution starts there.
• At that location is the initial bootstrap program.
• This program is in the form of read-only memory (ROM), because the RAM is in
an unknown state at system startup.
• ROM is convenient because it needs no initialization and cannot easily be infected
by a computer virus
System Boot
• The bootstrap program can perform a variety of tasks.
• Usually, one task is to run diagnostics to determine the state of the machine.
• If the diagnostics pass, the program can continue with the booting steps.
• It can also initialize all aspects of the system, from CPU registers to device
controllers and the contents of main memory.
• Sooner or later, it starts the operating system.
• A problem with this approach is that changing the bootstrap code requires changing
the ROM hardware chips.
• Some systems resolve this problem by using erasable programmable read-only
memory (EPROM), which is read-only except when explicitly given a command to
become writable.
System Boot
• For large operating systems (including most general-purpose operating systems
like Windows, Mac OS X, and UNIX) or for systems that change frequently, the
bootstrap loader is stored in firmware, and the operating system is on disk.
• In this case, the bootstrap runs diagnostics and has a bit of code that can read a
single block at a fixed location (say block zero) from disk into memory and
execute the code from that boot block.
• The program stored in the boot block may be sophisticated enough to load the
entire operating system into memory and begin its execution.
• GRUB (Grand Unified Boot Loader) is an example of an open-source bootstrap
program for Linux systems. It also allows user to chose the OS to be booted, in
case more than one OS available in the system.
Linux Boot Process