Operating System - Compressed
Operating System - Compressed
Unit-1
Services of OS
• User Interface
• Program Execution
• I/O Operation
• File System Manipulation
• Communication(Inter-process Communication)
• Error Detection
• Resource Allocation
• Accounting
• Protection & Security
Goals of OS
• Convenience (User-Friendly)
• Efficiency
• Portability
• Reliability
• Scalability
• Robustness
Components
• A computer system can be divided roughly into four components: the
hardware/ the operating system, the application programs/ and the
users (Figure 1.1).
• The hardware- the central processing unit, the memory, and the
input/output devices-provides the basic computing resources for the
system.
• The application programs- word processors/ spreadsheets/
compilers, and Web browsers-define the ways in which these
resources are used to solve users' computing problems.
• The operating system controls the hardware and coordinates its use
among the various application programs for the various users.
Abstract View of Computer System
•.
Components of Computer System
A computer system can be divided into four components, which are as follows −
• Hardware − The hardware is the physical part which we can touch and feel, the central processing unit
(CPU), the memory, and the input/output (I/O) devices are the basic computing resources of a computer
system.
• Application programs − Application programs are user or programmer created programs like compilers,
database systems, games, and business programs that define the ways in which these resources can be used
to solve the computing problems of the users.
• Users − There are different types of users like people, machines, and even other computers which are trying
to solve different problems.
• Operating system − An operating system is the interface between the user and the machine which controls
and coordinates the use of the hardware among the various application programs for the various users.
Layered Structure
• Layered Structure is a type of system structure in which the different services of the operating system are
split into various layers, where each layer has a specific well-defined task to perform.
• It was created to improve the pre-existing structures like the Monolithic structure ( UNIX ) and the Simple
structure ( MS-DOS ).
• Example – The Windows NT operating system uses this layered approach as a part of it.
Design Analysis :
The whole Operating System is separated into several layers ( from 0 to n ) as the diagram shows. Each of the
layers must have its own specific function to perform. There are some rules in the implementation of the layers
as follows:
• The outermost layer must be the User Interface layer.
• The innermost layer must be the Hardware layer.
• A particular layer can access all the layers present below it but it cannot access the layers present above it.
That is layer n-1 can access all the layers from n-2 to 0 but it cannot access the nth layer.
Layered OS Design
• According to the computer system, the operating system is the bridge between
applications and hardware. It is most intimate with the hardware and is used to
control it as required.
• The system views the operating system as a resource allocator. There are many
resources such as CPU time, memory space, file storage space, I/O devices etc.
that are required by processes for execution. It is the duty of the operating
system to allocate these resources judiciously to the processes so that the
computer system can run as smoothly as possible.
• The operating system can also work as a control program. It manages all the
processes and I/O devices so that the computer system works smoothly and
there are no errors. It makes sure that the I/O devices work in a proper manner
without creating problems.
• Operating systems can also be viewed as a way to make using hardware easier.
Classification of Operating system
• Batch OS
• Multi-programming OS
• Multitasking OS/Time sharing OS
• Multiprocessing OS
• Real-Time OS
• Distributed OS
• Embedded OS
• Clustered OS
Batch OS
• In this technique, similar types of jobs were batched together and executed in time. People were
used to having a single computer which was called a mainframe.
• In Batch operating system, access is given to more than one person; they submit their respective
jobs to the computer operator which in turn makes batches of similar jobs for the execution.
• The system put all of the jobs in a queue on the basis of first come first serve and then executes
the jobs one by one. The users collect their respective output when all the jobs get executed.
• The purpose of this operating system was mainly to transfer control from one job to another as
soon as the job was completed.
Advantages of Batch Operating System:
• Multiple CPUs are interconnected so that a job can be divided among them for faster execution. When a job
finishes, results from all CPUs are collected and compiled to give the final output.
• These systems have multiple processors working in parallel that share the computer clock, memory, bus,
peripheral devices etc.
• Multiple CPUs can also be used to run multiple jobs simultaneously.
Advantages of multiprocessing operating system are:
• Increased reliability: Due to the multiprocessing system, processing tasks can be distributed among several
processors. This increases reliability as if one processor fails; the task can be given to another processor for
completion.
• Increased throughout: As several processors increase, more work can be done in less
• The economy of Scale: As multiprocessors systems share peripherals, secondary storage devices, and power
supplies, they are relatively cheaper than single-processor systems.
Disadvantages of Multiprocessing operating
System
• Increased Expense
Even though multiprocessor systems are cheaper in the long run than using multiple computer
systems, still they are quite expensive. It is much cheaper to buy a simple single processor system
than a multiprocessor system.
• Complicated Operating System Required
There are multiple processors in a multiprocessor system that share peripherals, memory etc. So, it
is much more complicated to schedule processes and impart resources to processes than in single
processor systems. Hence, a more complex and complicated operating system is required in
multiprocessor systems.
• Large Main Memory Required
All the processors in the multiprocessor system share the memory. So a much larger pool of
memory is required as compared to single processor systems.
Types of multiprocessing systems
• In an asymmetric multiprocessing system, there is a master slave relationship between the processors.
• Further, one processor may act as a master processor or supervisor processor while others are treated as
shown below:
• Maximum consumption –
Maximum utilization of devices and systems. Thus more output from all the resources.
• Task Shifting –
Time assigned for shifting tasks in these systems is very less. For example, in older systems, it takes about 10
microseconds. Shifting one task to another and in the latest systems, it takes 3 microseconds.
• Focus On Application –
Focus on running applications and less importance to applications that are in the queue.
• Real-Time Operating System In Embedded System –
Since the size of programs is small, RTOS can also be embedded systems like in transport and others.
• Error Free –
These types of systems are error-free.
• Memory Allocation –
Memory allocation is best managed in these types of systems.
Disadvantages:
• Limited Tasks –
Very few tasks run simultaneously, and their concentration is very less on few applications to
avoid errors.
• Complex Algorithms –
The algorithms are very complex and difficult for the designer to write on.
Kernel-mode
• When the system boots, the system starts with kernel mode. And the applications are executed in user
mode. The switch can happen from user mode to kernel mode when
• Interrupt occurs
• Need to access privileged instruction
• Need to access any device
• The mode bit is changed from 0 to 1 in case of the system switch back to user mode.
Modes of Operation
System Calls
• System calls serve as the interface between an operating system and a process. A system calls in computing
is the programmatic method by which a computer program asks the kernel of the operating system it is
running on for a service.
• User programmers can communicate with the operating system to request its services using the interface
that is created by a system call.
• When a process in user mode needs access to a resource, system calls are typically generated. The resource
is then requested from the kernel via a system call.
How system call works ?
Example of System Calls
There are primarily 5 different types of system calls in the operating system:
1. Process Control: The following services are provided by Process Control System calls that are used to control
a process:
• To forcefully abort the process, simply end it normally.
• Execute a process after loading it into the main memory.
• Terminate the current process before starting a new one.
• Wait for a process to complete running. Wait until a specific event happens, then announce its.
• Allocate memory to a process, then release the memory if the process is terminated.
2. File Management: The following services are provided by system call for file management:
• Making and erasing files ,Open the file, then close it, Write to a specific file, read from a specific file.
• To obtain a file's attribute and to change a file's attribute
Types of System Calls in OS(1)(Categories)
3. Device Management: The following services are offered by a system call that controls I/O devices:
• Devices might be needed while a process is running. such as access to the file system, I/O devices, main
memory, etc.
• As a result, it can ask for a device and then release it once the task is complete.
• when a requested device is granted access by the process. It is capable of reading, writing, and repositioning
operations.
• In order to obtain or modify a specific device's attribute.
• To detach a device from the processor that is currently executing a command, the call can be made.
4. Information Maintenance: The system calls for information maintenance call moves data from the user
program to the operating system. Considering this, the services offered by this type of system call are:
• Obtain the system's time or date. Set the system's time or date.
• Obtain system-related information. Configure the system data.
Types of System Calls in OS(2) (Categories)
• Obtain the characteristics of a specific operating system process. Alternatively, of a specific file on the system
or on any attached devices.
• Set the characteristics of a specific operating system process. Alternatively, of a specific file on the system or
on any attached devices.
5. Communication: Such a system call facilitates the system's network connection. The services that these
system calls offer are:
• Open a fresh connection to send the data. After the transmission is finished, disconnect from the
connection.
• On a particular connection, send a message. Obtain communication from a specific connection.
• Identify and connect a specific remote device to the network. Remove a specific remote computer or device
from the network.
Examples of Types of System Calls
Important System Calls Used in OS
1. wait()
• In certain systems, a process must wait for another process to finish running before continuing. When a parent process
creates a child process, the parent process's execution is suspended until the child process has finished running.
• With a wait() system call, the parent process is automatically suspended. Control returns to the parent process once the
child process has completed its execution.
2. fork()
• The fork system call in OS is used by processes to make copies of themselves. By using this system, the Call parent process
can create a child process, and the parent process's execution will be halted while the child process runs.
3. exec()
• When an executable file replaces an earlier executable file within the context of an active process, this system call is
executed. The original process identifier is still present even though a new process is not created; instead, the new
process replaces the old one's stack, data, head, data, etc.
4. kill()
• The OS uses the kill() system call to urge processes to terminate by sending them a signal. A kill system call can have
different meanings and is not always used to end a process.
5. exit()
• An exit system call is used when the programme must be stopped. When the exit system call is used, the resources that
the process was using were released.
Fork() system call
• The fork() System Call is used to create processes. It does not take any arguments and returns a process ID
(mostly an integer value).
• Fork system call creates a new process (called child process) that runs concurrently with the parent process
(the process that makes the fork() call).
Fork() return the following values:
• Negative value - it represents the creation of the child process was unsuccessful.
• Zero - it represents a new child process is created.
• Positive value - The process ID of the child process to the parent. The returned process ID is type pid_t defined in
sys/types.h. Usually, the process ID is an integer.
• Since the child and parent processes run concurrently, these processes reside in different memory spaces.
Code (Do refer class examples too)
Example1:
Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
//main function begins
int main()
{ fork();
fork();
fork();
printf("this process is created by fork() system call\n");
return 0; }
Output:
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
Here, the total number of processes created is 2^3 = 8, and the print statement is executed eight times.
Kernel(The Kernel is the heart of your operating system. Kernel handles all operations on
behalf of operating system.)
• A Kernel is a computer program at the core of a computer's operating system. It generally has complete
control over everything.
• It is one of the first programs to be loaded up on the memory before the boot loader. It manages the
memory as well as peripherals such as keyboards and monitors.
• It acts as a primary interface between the hardware and the processes of a computer. The Kernel connects
these two to adjust resources as effectively as possible.
Functions of a Kernel
• Device Management: Processes require various peripheral devices such as a mouse and keyboard connected
to the computer to perform various tasks. The Kernel manages the allocation of the peripheral devices.
• Resource Management: Kernel shares the resources between different processes while ensuring that every
process has unfirm access to the resources.
• Memory management: Every process requires some memory to execute. The Kernel allows the processes to
access the memory safely. It is responsible for allocating and deallocating memory to processes for their
execution.
• Access Computer Resource: A kernel can access different computer resources such as RAM, CPU, I/O
devices, and other resources. Every program needs to access the memory to execute. The Kernel decides
which memory each process will use, and the action is taken if memory is unavailable.
Types of Kernels
Monolithic Kernels (All the services run in kernel space.)
• The Kernel and user-space use the same memory space in a monolithic kernel. This means that no different
memory space is used for user services and kernel services.
• All the services are in kernel mode, and the entire kernel functionality is organized into a single block that is
difficult to debug and maintain.
• A monolithic kernel is an operating system architecture where the entire operating system is working in
kernel space.
• Example: Unix, Linux, XTS-400, etc.
Following are the primary functions of a monolithic kernel:
• This kernel provides file management, CPU scheduling, memory management, and other operating system
functions through system calls.
• It also provides complete control over components like Interprocess communication(IPC), I/O and device
management, fundamental process management, and hardware.
Monolithic Kernel
Advantages/Disadvantages
Advantages
• It gives better performance than the microkernel.
• There's no additional communication overhead, unlike microkernel.
• It provides effective services like IPC through system calls.
• A single extensive process can run entirely in a single address space which enhances the security of the
process as well from interference.
Disadvantages
• One of the major disadvantages of a monolithic kernel is that if anyone service fails it leads to an entire
system failure.
• If the user has to add any new service. The user needs to modify the entire operating system.
Microkernel
• In this type of Kernel, the user and Kernel services are implemented into two different address
spaces, i.e., user and kernel spaces.
• Only the most important services are inside the kernel and the rest of the OS services are present
inside the system application program. Thus users are able to interact with those not-so-
important services within the system application.
• the microkernel is solely responsible for the most important services of the operating system they
are named as follows: Inter process-Communication, Memory Management, CPU-Scheduling.
• The user services are kept in user address space, and kernel services are kept under kernel
address space, thus also reduces the size of kernel and size of an operating system as well.
• In microkernels, there will be no system crash when a process crashes, and it can be resolved by
just restarting the error-caused services.
Micro-Kernal
Monolithic VS Microkernel
S. No. Parameters Microkernel Monolithic kernel
In microkernel, user services and kernel services are kept in In monolithic kernel, both user services and kernel services are kept in
1. Address Space
separate address space. the same address space.
3. Size Microkernel are smaller in size. Monolithic kernel is larger than microkernel.
5. Coding To design a microkernel, more code is required. Less code when compared to microkernel
Failure of one component does not effect the working of micro Failure of one component in a monolithic kernel leads to the failure of
6. Failure
kernel. the entire system.
To implement IPC messaging queues are used by the Signals and Sockets are utilized to implement IPC in monolithic
9. Communication
communication microkernels. kernels.