Unit I
Introduction to Operating System
Definition and Purpose of Operating System:
An operating system acts as an intermediary between the user of a computer and computer
hardware.
The purpose of an operating system is to provide an environment in which a user can
execute programs in a convenient and efficient manner.
An operating system is software that manages the computer hardware.
The hardware must provide appropriate mechanisms to ensure the correct operation of the
computer system and to prevent user programs from interfering with the proper operation of
the system.
Operating System – Definition:
An operating system is a program that controls the execution of application programs and
acts as an interface between the user of a computer and the computer hardware.
An operating system is concerned with the allocation of resources and services, such as
memory, processors, devices, and information.
The operating system correspondingly includes programs to manage these resources, such as a
traffic controller, a scheduler, memory management module, I/O programs, and a file system.
Operating system as User Interface –
1. User
2. System and application programs
3. Operating system
4. Hardware
Every general-purpose computer consists of the hardware, operating system, system programs,
and application programs.
The hardware consists of memory, CPU, ALU, and I/O devices, peripheral device, and storage
device. System program consists of compilers, loaders, editors, OS, etc.
The application program consists of business programs, database programs.
Every computer must have an operating system to run other programs.
The operating system coordinates the use of the hardware among the various system programs
and application programs for various users.
It simply provides an environment within which other programs can do useful work.
The operating system is a set of special programs that run on a computer system that allows it
to work properly.
It performs basic tasks such as recognizing input from the keyboard, keeping track of files and
directories on the disk, sending output to the display screen and controlling peripheral devices.
OS is designed to serve two basic purposes:
1. It controls the allocation and use of the computing System’s resources among the various user
and tasks.
2. It provides an interface between the computer hardware and the programmer that simplifies
and makes feasible for coding, creation, debugging of application programs.
History and Evolution of Operating System
Operating systems have been evolving through the years.
In the 1950s, computers were limited to running one program at a time like a calculator, but
later in the following decades, computers began to include more and more software programs,
sometimes called libraries, that formed the basis for today’s operating systems.
The first Operating System was created by General Motors in 1956 to run a single IBM
mainframe computer, its name was the IBM 704.
IBM was the first computer manufacturer to develop operating systems and distribute them in
its computers in the 1960s.
Following is the timeline about Operating System evaluation:
Stanford Research Institute developed the ON-Line System (NLS) in the late 1960s, which was
the first operating system that resembled the desktop operating system we use today.
Microsoft bought QDOS (Quick and Dirty Operating System) in 1981 and branded it as Microsoft
Operating System (MS-DOS). As of 1994, Microsoft had stopped supporting MS-DOS.
Unix was developed in the mid-1960s by the Massachusetts Institute of Technology, AT&T
Bell Labs, and General Electric as a joint effort. Initially it was named MULTICS, which stands for
Multiplexed Operating and Computing System.
FreeBSD is also a popular UNIX derivative, originating from the BSD project at Berkeley. All
modern Macintosh computers run a modified version of FreeBSD (OS X).
Windows 95 is a consumer-oriented graphical user interface-based operating system built on
top of MS-DOS. It was released on August 24, 1995 by Microsoft as part of its Windows 9x
family of operating systems.
Solaris is a proprietary Unix operating system originally developed by Sun Microsystems in
1991. After the Sun acquisition by Oracle in 2010 it was renamed Oracle Solaris.
Types of Operating System
1. Batch Operating System:
A series of jobs are executed without any human intervention in Batch processing system.
In this set of jobs with similar needs are batched together and inputted to the computer for
execution.
It is also called as Simple Batch System. It is slower in processing than Multiprogramming
system.
Advantages of Batch Processing:
It manages large repeated work easily.
No special hardware and system support required to input data in batch systems.
It can be shared by multiple users.
Very less idle time of the batch system.
Enables us to manage the efficiently large load of work.
Disadvantages of Batch Processing:
It has more turnaround time.
It has Nonlinear behavior.
It has Irreversible behavior.
Due to any mistake, it may happen any job can go infinite loop.
This OS proves to be costly sometimes.
2. Multiprogramming Operating System
An operating system that is capable of running multiple programs on a single processor is
known as a multiprogramming operating system. If a program has to wait for an I/O transfer
in a multiprogramming operating system, other programs utilize the CPU and other resources.
One of the major aims of multiprogramming is to manage the various resources of the entire
system. Multiprogramming is the principle concept used by multiprogramming systems. These
resources include but are not restricted to, the file system, memory, processors, input and
output, etc.
Multiprogramming operating systems, therefore, are designed for storing and processing
several programs simultaneously (not necessarily in real-time, though; explained below). The
routines responsible for managing resources are made accessible to the core functions of the
operating system.
Advantages of Multiprogramming Operating System
The processor is utilized most of the time and rarely becomes idle unless there are no
jobs to execute.
The system is fast because all the jobs run parallel amongst themselves.
Multiprogramming OS supports multiple users on the computer system.
Resources utilization is efficient and even.
Total time required to execute a job reduced.
Disadvantages of Multiprogramming Operating System
Sometimes, processes requiring long CPU times have to wait for other jobs (usually
relatively shorter jobs) to finish.
It's not easy to keep track of a large number of processes in multiprogramming.
Multiprogramming OS is not an easy job owing to the complex nature of schedule
handling.
Multiprogramming OS has to use CPU scheduling.
Memory management should be very efficient.
While a program executes, there cannot be any interaction between it and the user.
3. Multitasking Operating System
In a modern computer system, the word “multitasking” is employed. It’s a logical extension of
the multiprogramming system that allows numerous applications to run simultaneously.
Multitasking in operating systems allows multiple tasks to run in an concurrent (or interleaved)
manner, enhancing system performance.
Multitasking in an OS enables a user to execute multiple computer tasks at the same time.
Processes that hold common processing resources, such as a CPU, are known as many tasks.
Apart from CPU utilization, it also improves user experience as the system becomes more
responsive and interactive, hence allows user to do multiple tasks.
Advantages of Multitasking Operating System:
Efficient CPU utilization by running multiple tasks concurrently.
Better system responsiveness and user experience.
Allows higher-priority processes to take precedence over lower-priority ones.
Disadvantages of Multitasking Operating System:
Context switching overhead, which can reduce performance.
Complexity in process synchronization and management.
Can lead to starvation if lower-priority processes are never allocated CPU time.
4. Real Time Operating System:
A real-time operating system (RTOS) is a special kind of operating system designed to handle
tasks that need to be completed quickly and on time. Unlike general-purpose operating systems
(GPOS), which are good at multitasking and user interaction, RTOS focuses on doing things in
real time.
Examples of real-time operating systems are airline traffic control systems, Command
Control Systems, airline reservation systems, Heart pacemakers, Network Multimedia Systems,
robots, etc.
Advantages of RTOS:
Maximum utilization of devices and systems. Thus more output from all the resources.
Focus on running applications and less importance to applications that are in the queue.
These types of systems are error-free.
Memory allocation is best managed in these types of systems.
Disadvantages of RTOS:
Very few tasks run simultaneously, and their concentration is very less on few
applications to avoid errors.
Sometimes the system resources are not so good and they are expensive as well.
The algorithms are very complex and difficult for the designer to write on.
Distributed Operating System:
A distributed operating system is a type of operating system that uses multiple central
processors to manage hardware resources and serve multiple real-time applications and users.
In a distributed operating system, all the jobs are distributed among multiple processors, which
communicate with each other via a single communication channel that works in both directions.
Each system in a distributed operating system has its own memory and processor.
A distributed operating system uses multiple central processing units (CPUs).
With distributed operating systems, all the jobs that are to be processed will be distributed
among the multiple processors.
Every system or node in the distributed operating system has its own memory as well as its own
processor.
Advantages of Distributed Operating System:
With the facility of being able to share resources of multiple systems, a user using one
particular site may be able to use the resources that are available at another site.
There is a significant decrease in the load on the system and delays in the processing of
data since there are multiple machines/nodes working on the processing of tasks.
According to the user's requirements, the size of the system can be set.
Disadvantages of Distributed Operating System:
The cost of setting up a distributed operating system is high.
The failure of the main system might affect the complete system.
Programming of a distributed operating system is complex.
5. Multiprocessing Operating System:
A Multi-Processing Operating System is a type of Operating System in which more than one CPU
is used for the execution of resources. It betters the throughput of the System.
Advantages of a Multi-Processing Operating System:
It increases the throughput of the system as processes can be parallelized.
As it has several processors, so, if one processor fails, we can proceed with another
processor.
Basic Operating System Functions
Operating System handles the following responsibilities:
Controls all the computer resources.
Provides valuable services to user programs.
Coordinates the execution of user programs.
Provides resources for user programs.
Provides an interface (virtual machine) to the user.
Hides the complexity of software.
Supports multiple execution modes.
Monitors the execution of user programs to prevent errors.
1. Process Management
Process management in operating system is about managing processes. A Process is a running
program.
The life cycle of process is from the moment program start until it finishes. Operating system
makes sure each process:
gets its turn to use the CPU
synchronized when needed
has access to the resources it needs, like memory, files, and input/output devices.
It also handles issues like process coordination and communication, while preventing conflicts
such as deadlocks. This way, the OS ensures smooth multitasking and efficient resource use.
2. Memory Management
Memory management is an essential task of the operating system that handles the storage and
organization of data in both main (primary) memory and secondary storage.
The OS ensures that memory is allocated and deallocated properly to keep programs running
smoothly.
It also manages the interaction between volatile main memory and non-volatile secondary
storage.
Key Activities in Memory Management:
Main Memory Management:
Memory Allocation: Assigns memory to processes using techniques like paging and
segmentation.
Memory Deallocation: Frees memory when no longer needed.
Memory Protection: Prevents processes from accessing each other’s memory.
Virtual Memory: Uses disk space as extra memory to run larger processes.
Fragmentation: Manages wasted memory space (internal/external) through compaction.
Secondary Memory Management:
Disk Space Allocation: Organizes how files are stored on the disk (contiguous, linked, indexed).
File System Management: Manages files and directories for efficient data access.
Free Space Management: Tracks available space on the disk.
Disk Scheduling: Organizes the order of disk read/write requests.
Backup and Recovery: Ensures data is backed up and can be restored after failure.
3. File System Management
File management in the operating system ensures the organized storage, access and control of
files.
The OS abstracts the physical storage details to present a logical view of files, making it easier
for users to work with data.
It manages how files are stored on different types of storage devices (like hard drives or SSDs)
and ensures smooth access through directories and permissions.
File System Management includes managing of:
File Attributes
File Name: Identifies the file with a name and extension (e.g., .txt, .jpg).
File Type: Defines the format of the file (e.g., text, image, executable).
Size: The amount of storage the file occupies.
Permissions: Determines who can read, write, or execute the file.
File Types
Text Files: Contain human-readable content (e.g., .txt, .md).
Binary Files: Store data in binary format (e.g., .jpg, .mp3).
Executable Files: Contain program code (e.g., .exe, .out).
Operations on Files
Create: Allows users to create new files.
Read: Opens files to read their contents.
Write: Modifies the contents of a file.
Delete: Removes a file from the system.
4. Device Management (I/O System):
Device management of an operating system handles the communication between the system
and its hardware devices, like printers, disks or network interfaces.
The OS provides device drivers to control these devices, using techniques like Direct Memory
Access (DMA) for efficient data transfer and strategies like buffering and spooling to ensure
smooth operation.
Major components in Device Management:
Device Drivers: The operating system uses device drivers to interact with hardware devices.
There are two types of device drivers:
Kernel-space drivers run in the OS kernel, offering direct access to hardware.
User-space drivers run outside the kernel and are more isolated, providing safety but less
performance.
Buffering & Caching:
Buffering temporarily stores data in memory to manage differences in device speeds. Block
devices (e.g., hard drives) use larger blocks of data for buffering, while character devices (e.g.,
keyboards, mice) use smaller, byte-by-byte buffering.
Caching improves access speed by storing frequently accessed data in a faster storage medium
(like RAM).
5. Protection and Security
Protection and security mechanisms in an operating system are designed to safeguard system
resources from unauthorized access or misuse.
These mechanisms control which processes or users can access specific resources (such as
memory, files, and CPU time) and ensure that only authorized users can perform specific
actions. While protection ensures proper access control, security focuses on defending the
system against external and internal attacks.
Access Control: The operating system ensures that processes and users can only access
resources they are authorized to. This is achieved through mechanisms like memory-addressing
hardware (which keeps processes within their own address space) and timer interrupts (which
prevent processes from monopolizing the CPU).
User Authentication: A system identifies users through user IDs (UIDs) or Security IDs (SIDs).
During login, the operating system verifies the user’s credentials, ensuring that only authorized
users can access their data or system resources.
Resource Protection: Mechanisms like file protection (ensuring only authorized users can
access or modify files) and device protection (restricting direct access to device-control
registers) ensure the integrity of system resources, preventing unauthorized or harmful use.
Security Against Attacks: Security mechanisms defend against external threats like viruses,
worms, denial-of-service attacks, and identity theft. These attacks can misuse system resources,
steal sensitive data, or disrupt system operation. The OS works to prevent these threats and
minimize damage.
Process Modes
An error in one program can adversely affect many processes, it might modify data of another
program or also can affect the operating system.
For example, if a process stuck in the infinite loop then this infinite loop could affect the correct
operation of other processes. So to ensure the proper execution of the operating system,
there are two modes of operation:
User mode:
When the computer system is run by user applications like creating a text document or using
any application program, then the system is in user mode.
When the user application requests for a service from the operating system or an interrupt
occurs or system call, then there will be a transition from user to kernel mode to fulfill the
requests.
Kernel Mode:
When the system boots, the hardware starts in kernel mode and when the operating system is
loaded, it starts user application in user mode.
To provide protection to the hardware, we have privileged instructions which execute only in
kernel mode. If the user attempts to run privileged instruction in user mode then it will treat
instruction as illegal and traps to OS.
Some of the privileged instructions are:
Handling Interrupts
To switch from user mode to kernel mode.
Input-Output management.
Need for Dual Mode Operations:
Certain types of tasks do not require any type of hardware support, that's why certain types of
processes are to be made hidden from the user. These tasks can be deal separately by using the
Dual Mode of the operating system.
The Kernel Level programs perform all the bottom level functions of the operating systems like
memory management, process management etc, for this purpose the operating system needs to
function in the Dual Mode. Dual Mode is necessary for specifying the access to the users only to
the tasks of their use in an operating system.
Basically, whenever the operating system works on the user applications, it held in the user
mode. When the user requests for some hardware services, a transition from User Mode to the
Kernel Mode occurs which is done by changing the mode bit from 1 to 0. Also the mode bit again
changed to 1 for returning back in the User Mode.
Advantages:
Protection: Dual-mode operation provides a layer of protection between user programs and
the operating system. In user mode, programs are restricted from accessing privileged
resources, such as hardware devices or sensitive system data. In kernel mode, the operating
system has full access to these resources, allowing it to protect the system from malicious or
unauthorized access.
Stability: Dual-mode operation helps to ensure system stability by preventing user programs
from interfering with system-level operations. By restricting access to privileged resources in
user mode, the operating system can prevent programs from accidentally or maliciously causing
system crashes or other errors.
Flexibility: Dual-mode operation allows the operating system to support a wide range of
applications and hardware devices. By providing a well-defined interface between user
programs and the operating system, it is easier to develop and deploy new applications and
hardware.
Security: Dual-mode operation enhances system security by preventing unauthorized access to
critical system resources. User programs running in user mode cannot modify system data or
perform privileged operations, reducing the risk of malware attacks or other security threats.
Efficiency: Dual-mode operation can improve system performance by reducing overhead
associated with system-level operations. By allowing user programs to access resources directly
in user mode, the operating system can avoid unnecessary context switches and other
performance penalties.
Reliability: Dual-mode operation enhances system reliability by preventing crashes and other
errors caused by user programs. By restricting access to critical system resources, the operating
system can ensure that system-level operations are performed correctly and reliably.
Disadvantages:
Performance: Dual-mode operation can introduce overhead and reduce system performance.
Switching between user mode and kernel mode requires a context switch, which can be time-
consuming and can impact system performance.
Security: Dual-mode operation can introduce security vulnerabilities. Malicious programs may
be able to exploit vulnerabilities in the operating system to gain access to privileged resources
or to execute malicious code.
Reliability: Dual-mode operation can introduce reliability issues as it is difficult to test and
verify the correct operation of both user mode and kernel mode. Bugs or errors in either mode
can lead to system crashes, data corruption, or other reliability issues.
Compatibility: Dual-mode operation can create compatibility issues as different operating
systems may implement different interfaces or policies for user mode and kernel mode. This can
make it difficult to develop applications that are compatible with multiple operating systems or
to migrate applications between different systems.
Maintenance complexity: Dual-mode operation can make maintenance and support more
complex due to the need to ensure compatibility and security across both user mode and kernel
mode. This can increase the cost and time required for system updates, patches, and upgrades.
Methods of Requesting System Services – System Calls and
System Programs
System Programs:
In an operating system a user is able to use different types of system programs and the system
program is responsible for all the application software performance of the computer.
The system programs are responsible for the development and execution of a program and they
can be used by the help of system calls because system calls define different types of system
programs for different tasks.
Purpose of using system program
System programs communicate and coordinate the activities and functions of hardware and
software of a system and also controls the operations of the hardware. An operating system is
one of the examples of system software. Operating system controls the computer hardware and
acts like an interface between the application software’s.
Types of System programs
The types of system programs are as follows −
Utility program
It manages, maintains and controls various computer resources. Utility programs are
comparatively technical and are targeted for the users with solid technical knowledge.
Few examples of utility programs are: antivirus software, backup software and disk tools.
Device drivers
It controls the particular device connected to a computer system. Device drivers basically act as
a translator between the operating system and device connected to the system.
Example − printer driver, scanner driver, storage device driver etc.
Directory reporting tools
These tools are required in an operation system to have some software to facilitate the navigation
through the computer system.
Example − dir, ls, Windows Explorer etc.
System Calls:
A system call is a programmatic way in which a computer program requests a service from the
kernel of the operating system on which it is executed.
A system call is a way for programs to interact with the operating system. A computer program
makes a system call when it requests the operating system's kernel.
System call provides the services of the operating system to the user programs via the
Application Program Interface(API).
System calls are the only entry points into the kernel system and are executed in kernel mode.
A user program can interact with the operating system using a system call. A number of
services are requested by the program, and the OS responds by launching a number of systems
calls to fulfill the request.
A system call can be written in high-level languages like C or Pascal or in assembly language. If
a high-level language is used, the operating system may directly invoke system calls, which are
predefined functions.
A system call is initiated by the program executing a specific instruction, which triggers a
switch to kernel mode, allowing the program to request a service from the OS. The OS then
handles the request, performs the necessary operations, and returns the result back to the
program.
System calls are essential for the proper functioning of an operating system, as they provide a
standardized way for programs to access system resources. Without system calls, each program
would need to implement its methods for accessing hardware and system services, leading to
inconsistent and error-prone behavior.
Services Provided by System Calls
Process Creation and Management
Main Memory Management
File Access, Directory, and File System Management
Device Handling(I/O)
Protection
Networking
Examples of a System Call in Windows and Unix
System calls for Windows and Unix come in many different forms. These are
listed in the table below as follows:
Process Windows Unix
CreateProcess() Fork()
Process Control ExitProcess() Exit()
WaitForSingleObject() Wait()
Process Windows Unix
Open()
CreateFile()
File manipulation Read()
ReadFile()
Write()
WriteFile()
Close()
SetConsoleMode() Ioctl()
Device Management ReadConsole() Read()
WriteConsole() Write()
GetCurrentProcessID() Getpid()
Information Maintenance SetTimer() Alarm()
Sleep() Sleep()
CreatePipe() Pipe()
Communication CreateFileMapping() Shmget()
MapViewOfFile() Mmap()
SetFileSecurity() Chmod()
Protection InitializeSecurityDescriptor() Umask()
SetSecurityDescriptorgroup() Chown()
How does System Call Work?
Users need special resources: Sometimes programs need to do some special things that can't
be done without the permission of the OS like reading from a file, writing to a file, getting any
information from the hardware, or requesting a space in memory.
The program makes a system call request: There are special predefined instructions to make
a request to the operating system. These instructions are nothing but just a "system call". The
program uses these system calls in its code when needed.
Operating system sees the system call: When the OS sees the system call then it recognizes
that the program needs help at this time so it temporarily stops the program execution and
gives all the control to a special part of itself called 'Kernel'. Now 'Kernel' solves the need of the
program.
The operating system performs the operations: Now the operating system performs the
operation that is requested by the program. Example: reading content from a file etc.
Operating system give control back to the program: After performing the special operation,
OS give control back to the program for further execution of program.