0% found this document useful (0 votes)
88 views85 pages

Unit-1 OS KCS-401

Uploaded by

mansviverma1881
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views85 pages

Unit-1 OS KCS-401

Uploaded by

mansviverma1881
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 85

Operating Systems

(BCS-401)

Introduction to Operating Systems


(UNIT-1)
Course Instructor:
Dr. Sanjeev Kumar
(Associate Professor, IT Department, KIET, Ghaziabad)
Operating Systems Syllabus (Unit-1)

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Introduction to Operating Systems
 An operating system is a program that manages a computer’s
hardware.
 It also provides a basis for application programs and acts as an
intermediary between the computer user and the computer
hardware.
 Some operating systems are designed to be convenient (like mobile
OS), others to be efficient (like mainframe OS), and others to be
some combination of the two (like PCs).

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
The components of a computer system

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Why to Learn Operating System?
 An Operating System (OS) is an interface between a
computer user and computer hardware. An operating system
is a software which performs all the basic tasks like file
management, memory management, process management,
handling input and output, and controlling peripheral devices
such as disk drives and printers.
 Some popular Operating Systems include Linux Operating
System, Windows Operating System, VMS, OS/400, AIX,
z/OS, etc.
Functions of OS
 Memory Management
 Processor Management
 Device Management
 File Management
 Security
 Control over system performance
 Job accounting
 Error detecting aids
 Coordination between other software and users
OS from two viewpoints (User view & System view)
 User View
 The user’s view of the computer varies according to the interface
being used.
 Some operating system (like in PCs) is designed mostly for ease of
use, with some attention paid to performance and none paid to
resource utilization.
 In other cases, a user sits at a terminal connected to a mainframe
or a minicomputer. operating system in such cases is designed to
maximize resource utilization— to assure that all available CPU
time, memory, and I/O are used efficiently and that no individual
user takes more than her fair share.
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
OS from two viewpoints (User view & System view) (Cont.)
 User View
 In still other cases, users sit at workstations connected to networks
of other workstations and servers.
 These users have dedicated resources at their disposal, but they
also share resources such as networking and servers.
 Some computers have little or no user view. For example,
embedded computers in home devices and automobiles may have
numeric keypads and may turn indicator lights on or off to show
status

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
OS from two viewpoints (User view & System view) (Cont.)
 System View
 From the computer’s point of view, the operating system is the
program most intimately involved with the hardware. In this
context, we can view an operating system as a resource allocator.
 A computer system has many resources that may be required to
solve a problem: CPU time, memory space, file-storage space, I/O
devices, and so on. The operating system acts as the manager of
these resources.
 Another view, as a control program, of an operating system
emphasizes the need to control the various I/O devices and user
programs.
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Classification of Operating Systems
 Batch Systems
 Uniprogramming OS (Single user single process e.g. MS-DOS)
 Multiprogramming Operating system
 Time sharing / Multitasking
 Multiprocessor Systems
 Multiuser Systems
 Real Time System
 Distributed
 Embedded
 Clustered
 Multithreaded Systems OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Batch Systems
 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 through operator.
 Example: IBM OS/360, IBM MVS, IBM z/OS.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Advantages & Disadvantages of Batch Operating System
Advantages
 Multiple users can share the batch systems
 The idle time for the batch system is very less
 It is easy to manage large work repeatedly in batch systems
Disadvantages
 It is very difficult to guess or know the time required for any job to complete.
 Batch systems are hard to debug
 The other jobs will have to wait for an unknown time if any job fails

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Multiprogramming Operating System
 Multiprogramming is an extension to batch processing where the
CPU is always kept busy. Each process needs two types of system
time: CPU time and IO time.
 Multiprogramming OS is an ability of an operating system that
executes more than one program using a single processor machine.
 More than one task or program or jobs are present inside the main
memory at one point of time.
 The OS could pick and start the execution of one of the jobs in
memory.
 Whenever the jobs does not need CPU that means the job is working
with I/O at that time the CPU is idle. At that time the OS switches
OPERATING SYSTEMS (BCS-401)
to another job in memory and CPU executes a portion ofAssociate
(Dr. Sanjeev Kumar, it till the
Professor, IT Dept. )
Multiprogramming Operating System

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Multiprogramming Operating System
 An appropriate measure of performance of a
Multiprogramming Operating System is throughput, which
is the ratio of the number of programs processed and the total time
taken to process them
 To optimize the throughput The kernel keeps a mix of CPU-bound
and I/O-bound programs in memory.
 Unix, Linux, Windows

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Time-Sharing (Multitasking ) Operating Systems
 Each task is given some time to execute so that all the tasks work
smoothly.
 Each user gets the time of CPU as they use a single system.
 These systems are also known as Multitasking Systems.
 The task can be from a single user or different users also.
 The time that each task gets to execute is called quantum.
 After this time interval is over OS switches over to the next task.
 E.g. Windows OS

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Time-Sharing (Multitasking ) Operating Systems
Advantages:
 Each task gets an equal opportunity
 CPU idle time can be reduced
 Better Resource Sharing
 Improved Productivity: Time-sharing allows users to work
concurrently
 Improved User Experience: Time-sharing provides an interactive
environment that allows users to communicate with the computer in
real-time

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Time-Sharing (Multitasking ) Operating Systems
Disadvantages: (Due to multiple users)
 High Overhead: Time-sharing systems have a higher overhead than
other operating systems due to the need for scheduling, context
switching, and other
 Complexity: Time-sharing systems are complex and require advanced
software to manage multiple users simultaneously. This complexity
increases the chance of bugs and errors
 Security Risks: With multiple users sharing resources, the risk of
security breaches increases. Time-sharing systems require careful
management of user access, authentication, and authorization to
ensure the security of data and software. OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Real Time Operating System (RTOS)
 Real-time operating system (RTOS) is an operating system intended
to serve real time application that process data as it comes in, mostly
without buffer delay.
 Real-time operating systems (RTOS) are used in environments
where a large number of events, mostly external to the computer
system, must be accepted and processed in a short time or within
certain deadlines.
 The processing in this type of system must occur within the specified
constraints. Otherwise, This will lead to system failure.
 Examples of the real-time operating systems: Airline traffic control
systems, Command Control Systems, Heart Pacemaker, Robot
etc.(e.g. RTOS-32) OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Real Time Operating System : Types
 Soft Real-Time System
 A soft real-time system is one in which performance is degraded but
not destroyed by failure to meet response-time constraints.
 If several tasks miss deadline, then the performance of the system is
said to have degraded.
 An example of a soft real-time task is web browsing. Normally,
after an URL (Uniform Resource Locater) is clicked, the
corresponding web page is fetched and displayed within a couple of
seconds on the average. However, when it takes several minutes to
display a requested page, we still do not consider the system to have
failed, but merely express that the performance of the system has
degraded. OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Real Time Operating System : Types
 Hard Real-Time operating system
 A hard real-time system is one in which failure to meet even a single
deadline may lead to complete or catastrophic system failure.
 The task deadlines are in the order of micro or milliseconds.
 Many hard real-time systems are safety critical
 Examples: Industrial Control Applications, Robots, Satellite
Launching Application.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
The advantages of real-time operating systems
 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 running Application –Focus is 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.
 Memory Allocation –Memory allocation is best managed in these types of systems(Predictable Memory
Access Times, Dynamic memory management algorithm)
Multiprocessor operating systems
 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.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Multiprocessor operating systems: Types
 The different fields of multiprocessor operating systems used are as
follows −
 Asymmetric Multiprocessor − Every processor is given seeded
tasks in this operating system, and the master processor has the
power for running the entire system. In the course, it uses the
master-slave relationship.
 Symmetric Multiprocessor − In this system, every processor
owns a similar copy of the OS, and they can make communication in
between one another. All processors are connected with peering
relationship nature, meaning it won’t be using master & slave
relation.
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
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 time.
 The economy of Scale: As multiprocessors systems share peripherals, secondary storage devices, and power n 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.

E.g. Linux kernel with support for symmetric multiprocessing


Multiprocessing vs Multiprocessor
Feature Multiprocessor Multiprocessing
Definition A computer with multiple CPUs or processors Execution of multiple processes concurrently
Processes communicate via inter-process
Communication CPUs share the same memory and bus communication mechanisms such as pipes, queues,
shared memory, etc.
Resource Sharing Resources (e.g., memory, I/O) are shared Each process has its own resources
Processes may be coordinated by the operating
Coordination Coordinated by the operating system
system or a higher-level framework
Scalability may be limited due to contention Scalability can be achieved by distributing processes
Scalability
among processors for shared resources across multiple cores or machines
Fault tolerance relies more on software-based
Higher fault tolerance due to redundancy in
Fault Tolerance mechanisms like process supervision and fault
hardware components
recovery
Performance can be impacted by contention for Performance can be more predictable as processes are
Performance
shared resources and synchronization overhead isolated and have dedicated resources
Symmetric Multiprocessing (SMP), Asymmetric Parallel computing frameworks like MPI, OpenMP,
Examples
Multiprocessing (AMP) and multiprocessing modules in Python
Multithreaded systems
 Multitasking is of two types: Processor based and thread based.
 Processor based multitasking is totally managed by the OS.
 However multitasking through multithreading can be controlled by
the programmer to some extent.
 A process is a program being executed. A process can be further
divided into independent units known as threads.
 A thread is like a small light-weight process within a process. Or we
can say a collection of threads is what is known as a process.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Multithreaded systems
 Threading is used widely in almost every field. Most widely it is seen
over the internet nowadays where we are using transaction
processing of every type like recharges, online transfer, banking etc.
 Threading is a segment which divide the code into small parts that
are of very light weight and has less burden on CPU memory so that
it can be easily worked out and can achieve goal in desired field.
 Windows with multicore CPU.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Multithreading on single-core CPU
 While a single-core CPU can only execute one instruction at a
time
 multithreading allows for concurrent execution of multiple
threads
 It can be achieved through the illusion of parallelism through time-
sharing. Threads are lightweight processes within a program that
can run concurrently.
 The operating system's thread scheduler manages the execution of
threads, allowing them to run for short time slices before
switching to another thread.
 Python provides a built-in threading module for working with
threads.
Example Program: Multithreading
Multi-User Operating System
 A multi-user operating system is an operating system that permits
several users to access a single system running to a single operating
system.
 Users will usually sit at terminals or computers connected to the
system via a network and other system machines like printers.
 A multi-user operating system varies from a connected single-user
operating system in that each user accesses the same operating
system from different machines.
 The main goal of developing a multi-user operating system is to use it
for time-sharing and batch processing on mainframe systems.
 E.g. Ubuntu server
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Is windows, a multiuser OS??
 Yes, Multiple users can simultaneously work on a single Windows OS, several
tools and features are available
 Remote Desktop Services (RDS):
RDS allows multiple users to connect to a Windows server simultaneously and
access their own individual desktop sessions
 Windows Virtual Desktop (WVD):
Windows Virtual Desktop is a cloud-based service provided by Microsoft Azure.
It allows multiple users to access virtualized Windows desktops and applications
hosted on Azure infrastructure.
 Third-Party Remote Access Solutions:These solutions offer features like
remote desktop access, virtual desktop infrastructure (VDI), and collaboration
tools for multiple users to work together on a single Windows OS.
Can we access Windows through mobile( as
a user from multiple users)
 Yes, you can use Remote Desktop Services (RDS) to connect
with a mobile device, provided that the mobile device has a
Remote Desktop client application installed.
 Install Microsoft Remote Desktop app for Android
 Obtain connection information( Or Connect through same
wifi) enable remote connection on windows. [ in Run open
system properties(sysdm.cpl→ Remote-> enable remote connection)
 Connect through client by first searching the system on
network.
Network Operating System
 An OS, which includes software to communicate with other
computers via a network is called Network Operating System.
 This allows resources such as files, application programs and printers
to be shared between computers. Such OS are specialized to
provide the networking services.
 A multiuser operating system primarily focuses on managing user
sessions and resources on a single computer system, whereas a
network operating system focuses on coordinating communication
and resource sharing across multiple computers and devices within a
network.
 NOS examples are : BSD (Berkeley System Distribution), Windows
NT etc. OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Distributed Operating System (DOS)
 Distributed System is a collection of autonomous computer systems that
are physically separated but are connected by a centralized computer
network that is equipped with distributed system software.
 A distributed operating system (DOS) is a system that allows multiple
independent computers to appear and function as a single coherent system.
 The autonomous computers will communicate among each system by
sharing resources and files and performing the tasks assigned to them.
 E.. Google file system is a distributed file system developed by Google for
storing and managing large volumes of data across multiple servers. It
operates across a distributed cluster of servers, allowing data to be stored
redundantly and accessed in parallel by multiple clients.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Comparative table
Feature Multiuser OS Distributed OS Network OS
Facilitates
Allows multiple users to Manages a group of
communication and
Definition access and use a single independent computers
resource sharing among
system. as a unified system.
networked computers.
Coordinates
Manages user sessions Treats multiple
communication and
Scope and resources on a single computers as a single,
resource sharing across a
system. coherent system.
network.
Users interact with
Users interact with the Users interact with the
networked resources
User Interaction system through local distributed system as a
through client-server
sessions. single entity.
architecture.
Resources are shared
Resources are shared
Users share resources among networked
among multiple
(e.g., CPU, memory, computers via network
Resource Sharing computers in the
files) on a single system. protocols.
distributed system.
e.g. windows, unix E.g. windows server.
e.g. Google file system
Novell Netware
Services of OS: An operating system provides an environment for the execution of programs.
It provides certain services to programs and to the users of those programs

• User Interface
• Program Execution
• I/O Operation
• File System
Manipulation
• Communication(Inter-
process
Communication)
• Error Detection
• Resource Allocation
OS Services view of computer
• Accounting
• Protection & Security
Operating System Services
 Operating system services provides functions that are helpful to
the user.
 User interface:
 One is a command-line interface (CLI), which uses text commands and a
method for entering them (say, a keyboard for typing in commands in a specific
format with specific options).
 Another is a batch interface, in which commands and directives to control
those commands are entered into files, and those files are executed.
 Graphical user interface (GUI) is a window system with a pointing device to
direct I/O, choose from menus, and make selections and a keyboard to enter
text.
 Some systems provide two or all three of these variations.
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Operating System Services (cont.)
 Program execution. The system must be able to load a program into
memory and to run that program. The program must be able to end its
execution, either normally or abnormally (indicating error).
 I/O operations. A running program may require I/O, which may involve
a file or an I/O device. For efficiency and protection, users usually cannot
control I/O devices directly. Therefore, the operating system must provide
a means to do I/O.
 File-system manipulation. programs need to read and write files and
directories. They also need to create and delete them by name, search for a
given file, and list file information. Some operating systems include
permissions management to allow or deny access to files or directories
based on file ownership.
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Operating System Services (cont.)
 Communications. There are many circumstances in which one process
needs to exchange information with another process. Such communication
may occur between processes that are executing on the same computer or
between processes that are executing on different computer systems tied
together by a computer network.
 Communications may be implemented via shared memory, in which
two or more processes read and write to a shared section of memory, or
message passing, in which packets of information in predefined formats
are moved between processes by the operating system.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Operating System Services (cont.)
Error detection. The operating system needs to be detecting and
correcting errors constantly.
 Errors may occur in the CPU and memory hardware (such as a memory
error or a power failure), in I/O devices (such as a parity error on disk, a
connection failure on a network, or lack of paper in the printer), and in the
user program (such as an arithmetic overflow, an attempt to access an
illegal memory location, or a too-great use of CPU time).
 For each type of error, the operating system should take the appropriate
action to ensure correct and consistent computing.
 Sometimes, it has no choice but to halt the system. At other times, it might
terminate an error-causing process or return an error code to a process for
the process to detect and possibly correct.
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Operating System Services (cont.)
 Operating system functions exists for ensuring the
efficient operation of the system itself.
 Resource allocation. When there are multiple users or multiple
jobs running at the same time, resources must be allocated to each of
them.
 The operating system manages many different types of
resources. For instance, in determining how best to use the CPU,
operating systems have CPU-scheduling routines that take into
account the speed of the CPU, the jobs that must be executed, the
number of registers available, and other factors. There may also be
routines to allocate printers, USB storage drives, and other
peripheral devices. OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Operating System Services (cont.)
 Security –
The operating system uses password protection to protect user data
and similar other techniques. it also prevents unauthorized access to
programs and user data.
 Control over system performance –
Monitors overall system health to help improve performance.
records the response time between service requests and system
response to having a complete view of the system health. This can
help improve performance by providing important information
needed to troubleshoot problems. (Task Manager)

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Operating System Services (cont.)
 Job accounting –
Operating system Keeps track of time and resources used by various
tasks and users, this information can be used to track resource usage
for a particular user or group of users.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Goals of OS

• Convenience (User-Friendly): User-friendly interfaces, such as graphical user


interfaces (GUIs) and command-line interfaces (CLIs), enable users to interact with
the system effortlessly.
• Efficiency: Operating systems strive to efficiently manage CPU, memory, disk, and
other resources, minimizing wastage and maximizing throughput.
• Portability: Portability refers to the ability of the operating system to run on
different hardware platforms with minimal modifications
• Reliability: Reliable operating systems minimize downtime, prevent system crashes,
and recover gracefully from errors or failures.
• Scalability: Features like multiprocessing, multithreading, and distributed
computing support scalability by enabling parallelism and resource sharing.
• Robustness: Robust operating systems incorporate security measures, access
controls, and data integrity checks to protect against unauthorized access, malware,
and data corruption.
System Calls
 System calls provide an interface to the services made available by an
operating system.
 These calls are generally available as routines 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.
 An example to illustrate how system calls are used: writing a
simple program to read data from one file and copy them to another file.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
System Calls
 (CLI) In an interactive system, this approach will require a sequence of
system calls, first to write a prompting message on the screen and then to
read from the keyboard the characters that define the two files.
 (GUI) On mouse based and icon-based systems, a menu of file names is
usually displayed in a window. The user can then use the mouse to select
the source name, and a window can be opened for the destination name to
be specified.
 This sequence requires many I/O system calls.
 Even simple programs may make heavy use of the operating system.
Frequently, systems execute thousands of system calls per second.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
System Calls (Cont.)
 An example to illustrate how system calls are used: writing a
simple program to read data from one file and copy them to another file.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
System Calls (Cont.)
 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.
 Three of the most common APIs available to application programmers are
Windows API for Windows systems, POSIX API for POSIX -based
systems(Unix, Linux) and the Java API for programs that run on the Java
virtual machine.
 A programmer accesses an API via a library of code provided by the
operating system. In the case of UNIX and Linux for programs written in
the C language, the library is called libc
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
System Calls (Cont.)
Why would an application programmer prefer programming according to
an API rather than invoking actual system calls?
 Designing a program using an API can expect her program to compile and
run on any system that supports the same API
 Actual system calls can often be more detailed and difficult to work with
than the API available to an application programmer.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Types of System Calls
 System calls can be grouped roughly into six major categories: process
control, file manipulation, device manipulation, information
maintenance, communications, and protection.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Types of System Calls

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Types of System Calls

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
system call interface
 For most programming languages, the run-time support system (a set of
functions built into libraries included with a compiler) provides a
systemcall interface that serves as the link to system calls made
available by the operating system.
 The system-call interface intercepts function calls in the API and invokes
the necessary system calls within the operating system.
 Typically, a number is associated with each system call, and the system-call
interface maintains a table indexed according to these numbers.
 The system call interface then invokes the intended system call in the
operating-system kernel and returns the status of the system call and any
return values.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
systemcall interface (cont.)
 The caller need know nothing about how the system call is implemented or
what it does during execution. Rather, the caller need only obey the API
and understand what the operating system will do as a result of the
execution of that system call.
 Thus, most of the details of the operating-system interface are hidden from
the programmer by the API and are managed by the run time support
library.
 The relationship between an API, the system-call interface, and the
operating system is shown in Figure (next slide)…

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Programming example of System
call
#include<unistd.h> // provides access to various POSIX
(Portable Operating System Interface) system calls of linux.
void main()
{ int n;
char b[10];
n=read(0,b,10)
write(1,b,n)
} Practice on virtual Linux using nano
editor(https://bellard.org/jslinux/vm.html?url=alpine-x86.cfg&mem=192)
systemcall interface (cont.)

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
OS commands also uses System calls
Many of the OS commands through Windows Command
Prompt interface correspond to system calls, as they interact
with the underlying operating system to perform tasks such
as file manipulation, process management, and system
information retrieval.
 dir, mkdir, rmdir, echo, type, copy, move, del, cls:
These commands interact with the file system, making
system calls to perform tasks like listing directory contents,
creating and removing directories, displaying or manipulating
file contents, copying, moving, or deleting files.
 ipconfig, ping, netstat,tracert,nslookup: These commands
are related to networking and are directly related with system calls
for execution.
 tasklist, taskkill: These commands interact with the system's
process management.
 systeminfo: This command retrieves various system
configuration information such as OS version, hardware
configuration
 shutdown: This command initiates a system shutdown or restart.
shutdown /s /t 0 // Shutdown immediately
shutdown /r /t 0 // Restart immediately
e.g. How dir command make use of system
call
 Several system calls are involved
 Parsing the Command: First, the command prompt parses the dir
command.
 Loading the Command: It locates the executable file associated with the dir
command using available as build in command of cmd.exe
 Execution: The command interpreter (cmd.exe) issues system calls to the
Windows kernel to perform the directory listing operation.
 File System Interaction: The kernel interacts with the file system using
system calls such as FindFirstFile and FindNextFile retrieve information
about the files and directories in the current directory.
 Display Output: Finally, the command interpreter receives the results from
the kernel and displays
for different commands are given
below.
 Ipconfig ( Open, GetAdapterInfo, GetIpAddrTable,
writeConsole)
 taskkill( OpenProcess, terminateProcess, CloseHandle,
writeConsole)
Operating-System Operations
 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.
 Without protection against different sorts of errors, either
the computer must execute only one process at a time or
all output must be suspect.
 Solution is ‘Dual Mode Operation’.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Dual-Mode Operation
 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).
 With the mode bit, we can distinguish between a task that is
executed on behalf of the operating system and one that is
executed on behalf of the user.
 The OS switches between user mode and kernel mode to
fulfill the requests. OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Dual-Mode Operation

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Need of 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.
 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.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Example Privileged Instructions
 Context switching
 Disabling interrupts
 Clear memory of process
 Changing the memory map
 Reading or writing file
Kernel of an Operating System
 Kernel is central component of an operating system that manages
operations of computer and hardware.
 When computer boots kernel is first part to load in memory.
 Kernel acts as a bridge between applications and data processing
performed at hardware level using inter-process communication
and system calls.
 The kernel also provides a set of system calls, which are used by
programs to request services from the operating system.
 For example, when a program needs to read data from a file, it can
make a system call to the kernel to perform the file input/output
operation on its behalf.
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Operating-System Structure: Simple and limited Structure
 Many operating systems started as small, simple, and
limited systems and then grew beyond their original
scope.
 It was written to provide the most functionality in the
least space, so it was not carefully divided into modules.
 MS-DOS is an example of such a system. It was
originally designed and implemented by a few people
who had no idea that it would become so popular.
 In MS-DOS , the interfaces and levels of functionality
are not well separated. i.e. application programs are able
to access the basic I/O routines to write directly to the
display and disk drives.
 Such freedom leaves MS-DOS vulnerable to errant (or
malicious) programs, causing entire system crashes
when user programs fail.
 Intel 8088 for which it was writtenOPERATING
provides no(BCS-401)
SYSTEMS dual
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
mode and no hardware protection,
Types of Kernel: Monolithic Kernel
 A monolithic kernel is an operating system architecture where the
entire operating system is a single large program, or kernel, that
runs in privileged mode.
 This kernel contains all the necessary functions and services to
manage system resources, such as memory management, process
management, device drivers, and file systems.
 All the system services and device drivers run in the same address
space as the kernel, which makes the system more efficient in
terms of speed and resource utilization.
 However, this also means that a single bug or error in the kernel
can bring down the entire system.
 Example Linux, Unix, and earlier versions of Microsoft Windows.
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Types of Kernel: Monolithic Kernel

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Layered Approach
 With proper hardware support,
operating systems can be broken
into pieces that are smaller and
more appropriate than those
allowed by the original MS-DOS
and UNIX systems.
 Layered approach, in which
the operating system is broken
into a number of layers (levels).
The bottom layer (layer 0) is the
hardware; the highest (layer N) is
the user interface.
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
More on Layered Approach
 An operating-system layer is an implementation of an abstract object made up of
data and the operations that can manipulate those data.
 A typical operating-system layer—say, layer M—consists of data structures and a
set of routines that can be invoked by higher-level layers. Layer M, in turn, can
invoke operations on lower-level layers.
 Advantages: simplicity of construction and debugging
 Disadvantages: The major difficulty with the layered approach involves
appropriately defining the various layers.
 Because a layer can use only lower-level layers, careful planning is necessary.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Types of Kernel: Micro Kernel
 This method structures the operating system by removing all nonessential
components from the kernel and implementing them as system and user-
level programs.
 Most of the system services and device drivers run in user space, outside the
kernel's address space, which makes the system more modular and easier to
maintain.
 The main function of the microkernel is to provide communication between
the client program and the various services that are also running in user
space.
 Communication is provided through message passing.
 This also provides better isolation between different system components and
makes the system more robust and secure. However, the microkernel
architecture is usually slower and less efficient than a monolithic kernel due
to the overhead of inter-process communication. OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Micro Kernel Architecture

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Types of Kernel: Reentrant Kernel
 A reentrant kernel is a type of operating system kernel that
allows multiple programs or threads to execute concurrently
within the kernel space without interfering with each other.
 In other words, a reentrant kernel can be entered by multiple
processes or threads simultaneously without causing any
conflicts or crashes.
 The term "reentrant" comes from the fact that the kernel code
can be re-entered by multiple processes or threads without
causing any problems.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Example of Reentrant Kernel
 One example of a reentrant kernel is the Linux kernel.
 The Linux kernel allows multiple processes or threads to
execute concurrently within the kernel space without
interfering with each other.
 This is achieved through the use of locks, semaphores, and other
synchronization mechanisms that ensure that shared resources
are accessed in a safe and coordinated manner.

OPERATING SYSTEMS (BCS-401)


(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Example of Non-Reentrant Kernel
 An example of a non-reentrant kernel is the original UNIX kernel,
which was a monolithic kernel. In the original UNIX kernel, all
system services and drivers ran in the same address space, and
there was no support for concurrent execution of system calls.
 When a process made a system call in the original UNIX kernel, it
would temporarily halt the execution of all other processes while
it ran the system call.
 Later versions of UNIX, such as System V and BSD, added support
for reentrant system calls, which allowed multiple processes to
make system calls concurrently without interfering with each
other.
OPERATING SYSTEMS (BCS-401)
(Dr. Sanjeev Kumar, Associate Professor, IT Dept. )
Comparison Cont.
Compare following ?
 Applications Programs
 System Programs
 System Call Interface
 System Call
 Shell
 OS Kernel
 Device Drivers
 BIOS
Criteria Applicati System System Call System Call Shell OS Kernel Device Drivers BIOS
ons Programs Interface
Program
s
Function Programs Programs that The interface Requests made by Command-line Core component of Software Firmware program
directly provide tools or provided by the applications to the interface providing the operating components that stored on a
used by utilities for system operating system operating system interaction system responsible enable motherboard's
users to maintenance, to allow for specific between the user for managing communication ROM chip,
perform configuration, or applications to services or and the operating system resources between the responsible for
specific management. request services operations. system. and providing operating system low-level
tasks or from the kernel. essential services. and hardware initialization and
functions. devices. control functions
during the boot
process.

Interaction Interacted Accessed by users Accessed indirectly Invoked by Interprets user Accessed by Loaded and Executes
with to perform tasks by applications applications to commands and applications executed by the automatically
directly by such as file through function request services or provides an through system operating system during the boot
users management, disk calls or system perform interface for users calls to perform to manage process before the
through formatting, or calls. operations that to interact with the tasks such as communication operating system is
graphical system diagnostics. require privileged operating system. process with hardware loaded, with no
interfaces access. scheduling, devices. direct user
or memory interaction.
command- management, and
line I/O operations.
interfaces.
Examples Word Disk formatting System call APIs Functions like Command prompt Windows Kernel, Drivers for BIOS (Basic
processors, utilities, file provided by open, read, write, (e.g., Command Linux Kernel, printers, graphics Input/Output
web management tools, operating systems close, fork, exec in Prompt in macOS Kernel. cards, network System), UEFI
browsers, disk such as Windows Unix-like systems. Windows, Terminal adapters, storage (Unified Extensible
media defragmenters. API, POSIX API. in Unix-like devices. Firmware
players, systems). Interface).
Crit Applications System System Call System Call Shell OS Kernel Device Drivers BIOS
eria Programs Programs Interface
Priv Typically run Can be executed Runs with Executed with Typically runs Runs with Run with Executes with
ileg with user-level with user-level elevated user-level with user-level kernel-levelelevated elevated
es privileges. or elevated privileges to privileges, but privileges, but privileges to
privileges to privileges during
privileges interact with invokes kernel- can be elevated manage system
access hardware the boot process
depending on kernel-mode mode to perform resources and
directly and to initialize
the task. components. components for administrative provide coreperform hardware
privileged tasks. services. privileged components and
operations. operations. perform low-
level system
initialization.
Invo Invoked by users Invoked by users Invoked by Invoked by Interpreted and Always running Loaded and Automatically
cati to accomplish or system applications applications executed by the as part of the executed by the executed by the
on specific tasks or administrators through function through system operating operating operating hardware during
goals. to manage or calls or system calls to perform system in system, system as the boot process
configure the calls to request privileged response to user managing needed to to initialize
system. services. operations. commands. system manage hardware
resources and hardware components and
providing core devices. establish basic
services. system
functionality.
Booting Process in brief.
 Power On:
 You power on the computer by pressing the power button.
 BIOS Initialization:
 The Basic Input/Output System (BIOS) performs a Power-On Self-Test (POST) to check hardware components'
integrity.
 BIOS initializes hardware components such as the CPU, memory, and storage devices.
 Boot Device Detection:
 BIOS detects bootable devices such as hard drives or SSDs.
 Master Boot Record (MBR) Detection:
 BIOS locates the Master Boot Record (MBR) on the primary boot device.
 Bootloader Execution:
 BIOS loads the bootloader code from the MBR into memory.
 The bootloader continues the boot process by loading the operating system kernel.
 Operating System Boot:
 The operating system kernel initializes system resources and launches system services.
 The graphical user interface (GUI) or command-line interface (CLI) is loaded.
 Open required applications and run.
End of Unit-1
 Test Scheduled in next class
 Prepare well

You might also like