Operating System Unit-1
Operating System Unit-1
UNIT-1
An operating system (OS) is a program that acts as an interface
between the system hardware and the user. Moreover, it handles all
the interactions between the software and the hardware. All the
working of a computer system depends on the OS at the base level.
Further, it performs all the functions like handling memory, processes,
the interaction between hardware and software, etc.
or
Objectives of OS:
The primary goals of an operating system are as follows:
Convenience – An operating system improves the use of a machine.
Operating systems enable users to get started on the things they wish
to complete quickly without having to cope with the stress of first
configuring the system.
Efficiency – An operating system enables the efficient use of resources.
This is due to less time spent configuring the system.
Ability to evolve – An operating system should be designed in such a
way that it allows for the effective development, testing, and
introduction of new features without interfering with service.
Management of system resources – It guarantees that resources are
shared fairly among various processes and users.
*Features of Operating System (OS)
Here is a list important features of OS:
1.Protected and supervisor mode
2.Allows disk access and file systems Device drivers Networking Security
3.Program Execution
4.Memory management Virtual Memory Multitasking
5.Handling I/O operations
6.Manipulation of the file system
7.Error Detection and handling
8.Resource allocation
9.Information and Resource Protection
*Advantage of Operating System
1.Allows you to hide details of hardware by creating an abstraction
2.Easy to use with a GUI
3.Offers an environment in which a user may execute
programs/applications
4.The operating system must make sure that the computer system
convenient to use
5.Operating System acts as an intermediary among applications and the
hardware components
6.It provides the computer system resources with easy to use format
*Disadvantages of Operating System
1.If any issue occurs in OS, you may lose all the contents which have
been stored in your system.
2.Operating system’s software is quite expensive for small size
organization which adds burden on them. Example Windows
3.It is never entirely secure as a threat can occur at any time
*Operating System Generations:
Operating Systems have evolved over the years. So, their evolution
through the years can be mapped using generations of operating
systems. There are four generations of operating systems. These can be
described as follows −
Disadvantages:
2. Multi-programming OS:
Advantages of Multiprogramming OS
o Throughout the system, it increased as the CPU always had one
program to execute.
o Response time can also be reduced.
Disadvantages of Multiprogramming OS
o Multiprogramming systems provide an environment in which
various systems resources are used efficiently, but they do not
provide any user interaction with the computer system.
Network operating systems are the systems that run on a server and
manage all the networking functions. They allow sharing of various
files, applications, printers, security, and other networking functions
over a small network of computers like LAN or any other private
network. In the network OS, all the users are aware of the
configurations of every other user within the network, which is why
network operating systems are also known as tightly coupled systems.
Advantages of Network OS
Real-Time OS
The hard real-time OS is the operating system for mainly the applications in which
the slightest delay is also unacceptable. The time constraints of such applications
are very strict. Such systems are built for life-saving equipment like parachutes
and airbags, which immediately need to be in action if an accident happens.
The soft real-time OS is the operating system for applications where time
constraint is not very strict.
Advantages of Real-Time OS
Disadvantages of Real-Time OS
Advantages of Distributed OS
• Programming is complex.
It allows the user to perform more than one task at a time, each task
getting the same amount of time to execute. Hence, the name time
sharing OS. Moreover, it is an extension of multiprogramming systems. In
multiprogramming systems, the aim is to make the maximum use of the
CPU. On the other hand, here the aim is to achieve the minimum
response time of CPU.
Advantages of Time Sharing Operating System
• The data of each program should be secure so that they don’t mix.
• Communication is very important to maintain. Lack of
communication can affect the whole working.
The system call interface is the entry point for a program to interact with the
operating system. When a program makes a system call, it is transferring
control from the user mode to the kernel mode. The kernel mode is the
privileged mode of operation in which the operating system executes, and it has
access to all hardware resources. By making a system call, a program is asking
the operating system to perform a task on its behalf, such as reading or writing
data to a file, allocating memory, or creating a new process.
System calls are defined in the API of the operating system and are usually
written in a low-level language such as C or Assembly. These system calls are
designed to be as simple and efficient as possible so that they can be executed
quickly. They are usually implemented as a software interrupt or a trap, which
transfers control from the user-level program to the operating system.
2. File Management
Device management system calls: These system calls are used to manage and
manipulate I/O devices such as printers, keyboards, and disk drives. Examples
include ioctl() and select().
3. Device Management
Device management system calls: These system calls are used to manage and
manipulate I/O devices such as printers, keyboards, and disk drives. Examples
include ioctl() and select().
4. Information Management
Information maintenance system calls: These system calls are used to retrieve
information about the system, the processes running on the system, and the
status of various resources. Examples include getuid(), getgid(), and getpid().
5. Communication
These system calls are used for inter-process communication (IPC) and
resource working. Examples include socket(), bind(), listen(), and accept().
OR
1. Boot Loader: Only code stored in the system’s memory can be executed by
computers powered by the central processor unit. Nonvolatile memories are
used to store the code and data for modern operating systems and application
programmes. A computer must initially rely only on the code and data stored in
nonvolatile parts of the system’s memory when it is first turned on. The
hardware of the computer is unable to carry out numerous complex system
tasks since the operating system is not actually installed at boot time.
2. Boot Devices: The device from which the operating system is loaded is
known as the boot device. The Basic Input/Output System (BIOS) of a
contemporary PC supports booting from a variety of sources. These consist of a
USB device, network interface card, local hard drive, optical drive, floppy drive,
and a network card. A boot order can be set up by the user in the BIOS. When
the boot order is as follows:
• CD Drive
• Hard Disk Drive
• Network
3. Boot Sequence: Every personal computer uses the same basic boot
process. The CPU first executes a memory instruction for the BIOS. The
BIOS start-up program is transferred via a jump instruction in that
instruction. This programme performs a power-on self-test (POST) to
ensure that the hardware the computer will use is in good working order.
When it comes across a bootable device, the BIOS continues the
programmed boot sequence. When BIOS discovers a bootable device, it
loads the boot sector and switches control to it. It will be a master boot
record (MBR) if the boot device is a hard drive.
The MBR code looks for an active partition in the partition table. If
one is identified, the MBR code loads and executes the boot
sector of that partition. The boot sector is frequently operating
system specific. However, in most operating systems, its primary
job is to load and execute the operating system kernel, which
allows the operating system to continue booting. Assume there is
no active partition or the boot sector of the active partition is
faulty. The MBR may then load a secondary boot loader, which
will select a partition and load its boot sector, which normally
loads the operating system kernel.
Types of Booting:
There are two types of booting in an operating system.
1. Cold Booting: When a computer begins for the first time or when it is in a shutdown
state, and the power button is pressed to restart the system, this is known as cold
Booting. During cold Booting, the system reads all of the instructions from the ROM
(BIOS), and the Operating System is loaded into the system automatically. This type of
Booting takes longer than Hot or Warm Booting.
• When the power button is pressed or the system is reset, the computer’s
firmware (BIOS or UEFI) is invoked. It performs a Power-On Self-Test (POST)
to check hardware components, including memory, storage devices, and
peripherals. It then initializes the system and identifies bootable devices.
• Bootloader Execution:
• After the firmware completes the initial system checks, it searches for a
bootable device that contains the bootloader. The bootloader is a small
program responsible for loading the operating system into memory. The
firmware hands over control to the bootloader, which is typically stored in the
Master Boot Record (MBR) or EFI System Partition (ESP).
• The bootloader locates and loads the operating system kernel into memory.
The kernel is the core of the operating system that manages hardware,
memory, and other essential functions. The bootloader passes control to the
kernel, and the operating system begins its initialization.
• System Initialization:
• Once the kernel completes its initialization, it starts the user mode initialization.
User-specific settings, login prompts, and user applications/services are
loaded. The graphical user interface (GUI) or command-line interface (CLI) is
presented to the user, enabling interaction with the operating system.
• System Operation:
• After the booting process is complete, the operating system is ready for use.
The user can now run applications, access files, browse the internet, and
perform various tasks. The operating system manages system resources,
facilitates multitasking, and provides an interface for user interaction.
System Program:
System Programming can be defined as the act of building Systems Software
using System Programming Languages. According to Computer Hierarchy, one
which comes at last is Hardware. Then it is Operating System, System Programs,
and finally Application Programs. Program Development and Execution can be
done conveniently in System Programs. Some of the System Programs are
simply user interfaces, others are complex. It traditionally lies between the user
interface and system calls.
OR
System Programs are the collection of software required for program execution.
They are also known as system utilities. System programs can be simple,
involving only system calls as well as complex ones.
File Management
These are the programs that ask for information such as date and time,
number of users, or other information. These are the programs that
either copy this information to a file or in a graphical user interface,
display it on the screen. The registry is also involved in those that are
used to provide configuration-related information.
File Modification
These are the programs that are used to work with the files. These
include programs such as text editors that are used to create or modify
the contents of the file or perform operations such as searching and
replacing the contents of the file.
These include a set of programs that are required for the execution of
programs. Programs are loaded into the main memory and then
loaders, linkage editors, and other programs are required to perform
the execution. In some cases, debugging systems are also provided.
Communications
Focus It mainly focuses on external It mainly focuses on the internal threats of the
threats to the system. system.
Policy It specifies whether or not a It outlines which users are permitted to access a
specific user is allowed to certain resource.
access the system.
Queries It is a wide phrase that It comes with security and covers less complex
handles more complicated queries.
queries.
Process Management:
Process management involves various tasks like creation, scheduling,
termination of processes, and a dead lock. Process is a program that is
under execution, which is an important part of modern-day operating
systems. The OS must allocate resources that enable processes to
share and exchange information. It also protects the resources of each
process from other methods and allows synchronization among
processes.
Process Architecture
Process States
Minimize:
• CPU utilization
• Throughput
• Turnaround time
• Waiting time
• Response time
Waiting time- Once the execution starts, the scheduling process does
not hinder the time that is required for the completion of the process.
The only thing that is affected is the waiting time of the process, i.e the
time that is spent by a process waiting in a queue. The formula for
calculating KaTeX parse error: Expected 'EOF', got '–' at position 31:
…Turnaround Time –̲ Burst Time.
CPU Scheduling:
CPU Scheduling is a process of determining which process will own
CPU for execution while another process is on hold. The main task of
CPU scheduling is to make sure that whenever the CPU remains idle,
the OS at least select one of the processes available in the ready queue
for execution. The selection process will be carried out by the CPU
scheduler. It selects one of the processes in memory that are ready for
execution.
Types of CPU Scheduling
Here are two kinds of Scheduling methods:
Non-Preemptive Scheduling
In this type of scheduling method, the CPU has been allocated to a
specific process. The process that keeps the CPU busy will release the
CPU either by switching context or terminating. It is the only method
that can be used for various hardware platforms. That’s because it
doesn’t need special hardware (for example, a timer) like preemptive
scheduling.
Advantages of SJF
1. Maximum throughput
2. Minimum average waiting and turnaround time
Disadvantages of SJF
1. May suffer with the problem of starvation
2. It is not implementable because the exact Burst time for a process can't be known
in advance.
Priority Based Scheduling
Priority scheduling is a method of scheduling processes based on
priority. In this method, the scheduler selects the tasks to work as per
the priority.
Round-Robin Scheduling
Round robin is the oldest, simplest scheduling algorithm. The name of
this algorithm comes from the round-robin principle, where each person
gets an equal share of something in turn. It is mostly used for
scheduling algorithms in multitasking. This algorithm method helps for
starvation free execution of processes.
Each thread has its own program counter, stack, and set of registers.
But the threads of a single process might share the same code and
data/file. Threads are also termed as lightweight processes as they
share common resources.
Eg: While playing a movie on a device the audio and video are
controlled by different threads in the background.
OR
Single Thread Multithread process
Components of Thread
1. Program Counter
2. Register Set
3. Stack space
Multithreading:
In Multithreading, the idea is to divide a single process into multiple threads
instead of creating a whole new process. Multithreading is done to achieve
parallelism and to improve the performance of the applications as it is faster in
many ways which were discussed above. The other advantages of multithreading
are mentioned below.
Types of Threads
Threads are of two types. These are described below.
• User Level Thread
• Kernel Level Thread
User Level Thread is a type of thread that is not created using system calls. The
kernel has no work in the management of user-level threads. User-level threads
can be easily implemented by the user. In case when user-level threads are
single-handed processes, kernel-level thread manages them. Let’s look at the
advantages and disadvantages of User-Level Thread.
Advantages of User-Level Threads
• Implementation of the User-Level Thread is easier than Kernel Level Thread.
• Context Switch Time is less in User Level Thread.
• User-Level Thread is more efficient than Kernel-Level Thread.
• Because of the presence of only Program Counter, Register Set, and Stack
Space, it has a simple representation.
A kernel Level Thread is a type of thread that can recognize the Operating system
easily. Kernel Level Threads has its own thread table where it keeps track of the
system. The operating System Kernel helps in managing threads. Kernel
Threads have somehow longer context switching time. Kernel helps in the
management of threads.
Advantages of Kernel-Level Threads
• It has up-to-date information on all threads.
• Applications that block frequency are to be handled by the Kernel-Level
Threads.
• Whenever any process requires more time to process, Kernel-Level Thread
provides more time to it.
Disadvantages of Kernel-Level threads
• Kernel-Level Thread is slower than User-Level Thread.
• Implementation of this type of thread is a little more complex than a user-level
Thread.
Advantages of Threading:
• The semantics of fork() and exec() system calls: The fork() call is used to
create a duplicate child process. During a fork() call the issue that arises is
whether the whole process should be duplicated or just the thread which made
the fork() call should be duplicated. The exec() call replaces the whole
process that called it including all the threads in the process with a new
program.
Process vs Thread:
Process simply means any program in execution while the thread is a segment
of a process. The main differences between process and thread are mentioned
below:
Process Thread
Processes use more resources and hence they Threads share resources and hence they are termed as
are termed as heavyweight processes. lightweight processes.
Processes are totally independent and don’t A thread may share some memory with its peer threads.
share memory.
Each process is treated as a new process by the The operating system takes all the user-level threads
operating system as a single process.
If one process gets blocked by the operating If any user-level thread gets blocked, all of its peer
system, then the other process can continue threads also get blocked because OS takes all of them
the execution. as a single process.
If a process gets blocked, remaining processes If a user level thread gets blocked, all of its peer threads also
can continue execution.
get blocked.
All the different processes are treated All user level peer threads are treated as a single task by the
separately by the operating system.
operating system.
Processes require more time for creation. Threads require less time for creation.