0% found this document useful (0 votes)
15 views

Unit-I QISCET 2025

An operating system manages computer hardware and serves as an intermediary between users and hardware, facilitating efficient resource allocation. Various types of operating systems include batch systems, multiprogramming systems, and real-time systems, each designed to optimize different aspects of computing. The document also discusses the operations of modern operating systems, including dual-mode operation and process management.
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)
15 views

Unit-I QISCET 2025

An operating system manages computer hardware and serves as an intermediary between users and hardware, facilitating efficient resource allocation. Various types of operating systems include batch systems, multiprogramming systems, and real-time systems, each designed to optimize different aspects of computing. The document also discusses the operations of modern operating systems, including dual-mode operation and process management.
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/ 50

UNIT-1

OPERATING SYSTEMS OVERVIEW

1.1 Introduction
An operating system is a program that manages the computer hardware. It also provides a basis
for application programs and acts as an intermediary between the computer user and the
computer hardware. Operating systems are designed to be convenient and efficient. Because an
operating system is large and complex, it must be created piece by piece. Each of these pieces
should be a well-delineated portion of the system, with carefully defined inputs, outputs, and
functions.
A computer system can be divided roughly into four components: the hardware, the operating
system, the application programs, and the users.

Fig : Abstract view of the components of a computer system


The hardware—the central processing unit (CPU), the memory, and the input/output (I/O)
devices—provides the basic computing resources for the system.
The operating system controls and coordinates the use of the hardware among the various
application programs for the various users.
The application programs—such as word processors, spreadsheets, compilers, and web
browsers—define the ways in which these resources are used to solve users' computing
problems.
We can explore operating systems from two viewpoints

1
1. The user
2. The system.
A system is designed for one user to monopolize its resources. The goal is to maximize the work
(or play) that the user is performing. The operating system in multi user environment 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.
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.

1. Types of Operating Systems

Following are some of the most widely used types of Operating system.

1. Simple Batch System


2. Multiprogramming Batch System
3. Multiprocessor System
4. Desktop System
5. Distributed Operating System
6. Clustered System
7. Real-time Operating System
8. Handheld System

Simple Batch Systems:

 In this type of system, there is no direct interaction between user and the computer.
 The user has to submit a job (written on cards or tape) to a computer operator.
 Then computer operator places a batch of several jobs on an input device.
 Jobs are batched together by type of languages and requirement.

2
 Then a special program, the monitor, manages the execution of each program in the batch.
 The monitor is always in the main memory and available for execution.

Advantages of Simple Batch Systems

1. No interaction between user and computer.


2. No mechanism to prioritize the processes.

Multiprogramming Batch Systems:

 In this the operating system picks up and begins to execute one of the jobs from memory.
 Once this job needs an I/O operation operating system switches to another job (CPU and OS
always busy).
 Jobs in the memory are always less than the number of jobs on disk(Job Pool).
 If several jobs are ready to run at the same time, then the system chooses which one to run
through the process of CPU Scheduling.
 In Non-multiprogrammed system, there are moments when CPU sits idle and does not do
any work.
 In Multiprogramming system, CPU will never be idle and keeps on processing.

Time Sharing Systems are very similar to Multiprogramming batch systems. In fact time
sharing systems are an extension of multiprogramming systems.

3
In Time sharing systems the prime focus is on minimizing the response time, while in
multiprogramming the prime focus is to maximize the CPU usage.

Multiprocessor Systems:
A Multiprocessor system consists of several processors that share a common physical memory.
Multiprocessor system provides higher computing power and speed. In multiprocessor system all
processors operate under single operating system. Multiplicity of the processors and how they do act
together are transparent to the others.

Advantages of Multiprocessor Systems

1. Enhanced performance
2. Execution of several tasks by different processors concurrently, increases the system's throughput
without speeding up the execution of a single task.
3. If possible, system divides task into many subtasks and then these subtasks can be executed in
parallel in different processors. Thereby speeding up the execution of single tasks.

Desktop Systems:
Earlier, CPUs and PCs lacked the features needed to protect an operating system from user programs.
PC operating systems therefore were neither multiuser nor multitasking. However, the goals of

4
these operating systems have changed with time; instead of maximizing CPU and peripheral
utilization, the systems opt for maximizing user convenience and responsiveness. These systems are
called Desktop Systems and include PCs running Microsoft Windows and the Apple Macintosh.
Operating systems for these computers have benefited in several ways from the development of
operating systems for mainframes.

Microcomputers were immediately able to adopt some of the technology developed for larger
operating systems. On the other hand, the hardware costs for microcomputers are
sufficiently low that individuals have sole use of the computer, and CPU utilization is no longer
a prime concern. Thus, some of the design decisions made in operating systems for mainframes
may not be appropriate for smaller systems.

Distributed Operating System:


The motivation behind developing distributed operating systems is the availability of powerful
and inexpensive microprocessors and advances in communication technology.

These advancements in technology have made it possible to design and develop distributed
systems comprising of many computers that are inter connected by communication networks.
The main benefit of distributed systems is its low price/performance ratio.

Advantages Distributed Operating System

1. As there are multiple systems involved, user at one site can utilize the resources of systems at
other sites for resource-intensive tasks.
2. Fast processing.
3. Less load on the Host Machine.

Types of Distributed Operating Systems

Following are the two types of distributed operating systems used:

5
1. Client-Server Systems
2. Peer-to-Peer Systems

Client-Server Systems
Centralized systems today act as server systems to satisfy requests generated by client systems.
The general structure of a client-server system is depicted in the figure below:

Server Systems can be broadly categorized as: Compute Servers and File Servers.

 Compute Server systems, provide an interface to which clients can send requests to perform an
action, in response to which they execute the action and send back results to the client.
 File Server systems, provide a file-system interface where clients can create, update, read, and
delete files.

Peer-to-Peer Systems
The growth of computer networks - especially the Internet and World Wide Web (WWW) – has had
a profound influence on the recent development of operating systems. When PCs were introduced in
the 1970s, they were designed for personal use and were generally considered standalone computers.
With the beginning of widespread public use of the Internet in the 1990s for electronic mail and FTP,
many PCs became connected to computer networks.

In contrast to the Tightly Coupled systems, the computer networks used in these applications consist
of a collection of processors that do not share memory or a clock. Instead, each processor has its own
local memory. The processors communicate with one another through various communication lines,
such as high-speed buses or telephone lines. These systems are usually referred to as loosely coupled

6
systems ( or distributed systems). The general structure of a client-server system is depicted in the
figure below:

Clustered Systems:

 Like parallel systems, clustered systems gather together multiple CPUs to accomplish
computational work.
 Clustered systems differ from parallel systems, however, in that they are composed of two or
more individual systems coupled together.
 The definition of the term clustered is not concrete; the general accepted definition is that
clustered computers share storage and are closely linked via LAN networking.
 Clustering is usually performed to provide high availability.
 A layer of cluster software runs on the cluster nodes. Each node can monitor one or more of
the others. If the monitored machine fails, the monitoring machine can take ownership of its
storage, and restart the application(s) that were running on the failed machine. The failed
machine can remain down, but the users and clients of the application would only see a brief
interruption of service.
 Asymmetric Clustering - In this, one machine is in hot standby mode while the other is
running the applications. The hot standby host (machine) does nothing but monitor the active
server. If that server fails, the hot standby host becomes the active server.
 Symmetric Clustering - In this, two or more hosts are running applications, and they are
monitoring each other. This mode is obviously more efficient, as it uses all of the available
hardware.

7
 Parallel Clustering - Parallel clusters allow multiple hosts to access the same data on the
shared storage. Because most operating systems lack support for this simultaneous data
access by multiple hosts, parallel clusters are usually accomplished by special versions of
software and special releases of applications.

Clustered technology is rapidly changing. Clustered system's usage and it's features should expand
greatly as Storage Area Networks(SANs). SANs allow easy attachment of multiple hosts to
multiple storage units. Current clusters are usually limited to two or four hosts due to the complexity
of connecting the hosts to shared storage.

Real Time Operating System:


It is defined as an operating system known to give maximum time for each of the critical
operations that it performs, like OS calls and interrupt handling.

The Real-Time Operating system which guarantees the maximum time for critical operations and
complete them on time are referred to as Hard Real-Time Operating Systems.

While the real-time operating systems that can only guarantee a maximum of the time, i.e. the
critical task will get priority over other tasks, but no assurity of completeing it in a defined time.
These systems are referred to as Soft Real-Time Operating Systems.

Handheld Systems:
Handheld systems include Personal Digital Assistants (PDAs), such as Palm-Pilots or Cellular
Telephones with connectivity to a network such as the Internet. They are usually of limited size due to

which most handheld devices have a small amount of memory, include slow processors, and feature
small display screens.

 Many handheld devices have between 512 KB and 8 MB of memory. As a result, the operating
system and applications must manage memory efficiently. This includes returning all allocated
memory back to the memory manager once the memory is no longer being used.

8
 Currently, many handheld devices do not use virtual memory techniques, thus forcing program
developers to work within the confines of limited physical memory.

 Processors for most handheld devices often run at a fraction of the speed of a processor in a PC.
Faster processors require more power. To include a faster processor in a handheld device would
require a larger battery that would have to be replaced more frequently.
 The last issue confronting program designers for handheld devices is the small display screens
typically available. One approach for displaying the content in web pages is web clipping, where
only a small subset of a web page is delivered and displayed on the handheld device.

Some handheld devices may use wireless technology such as BlueTooth, allowing remote access
to e-mail and web browsing. Cellular telephones with connectivity to the Internet fall into this
category. Their use continues to expand as network connections become more available and
other options such as cameras and MP3 players, expand their utility.

1.2 OPERATING-SYSTEM OPERATIONS


Modern operating systems are interrupt driven. If thereare no processes to execute, no I/O
devices to service, and no users to whomto respond, an operating system will sit quietly, waiting
for something tohappen. Events are almost always signalled by the occurrence of an interruptor a
trap. A trap (or an exception) is a software-generated interrupt causedeither by an error (for
example, division by zero or invalid memory access)or by a specific request from a user program
that an operating-system servicebe performed. For each type of interrupt, separate segmentsof
code in the operating system determine what action should be taken. Aninterrupt service routine
is provided that is responsible for dealing with theinterrupt.
Dual-Mode Operation
In order to ensure the proper execution of the operating system, we must beable to distinguish
between the execution of operating-system code and userdefinedcode.
we need two separate modes of operation: user modeand kernel mode (also called supervisor
mode, system mode, or privilegedmode). A bit, called the mode bit, is added to the hardware
of the computer toindicate the current mode: kernel (0) or user (1). With the mode bit, we are
ableto distinguish between a task that is executed on behalf of the operating systemand one that
is executed on behalf of the user. When the computer system isexecuting on behalf of a user
application, the system is in user mode. However,when a user application requests a service from

9
the operating system (via asystem call), it must transition from user to kernel mode to fullfill the
request.This is shown in Figure 1.8.

At system boot time, the hardware starts in kernel mode. The operatingsystem is then loaded and
starts user applications in user mode. Whenever atrap or interrupt occurs, the hardware switches
from user mode to kernel mode(that is, changes the state of the mode bit to 0). Thus, whenever
the operatingsystem gains control of the computer, it is in kernel mode. The system
alwaysswitches to user mode (by setting the mode bit to 1) before passing control toa user
program.
The dual mode of operation provides us for protecting theoperating system from errant users—
and errant users from one another. Weaccomplish this protection by designating some of the
machine instructions thatmay cause harm as privileged instructions. The hardware allows
privilegedinstructions to be executed only in kernel mode. If an attempt is made toexecute a
privileged instruction in user mode, the hardware does not executethe instruction but rather treats
it as illegal and traps it to the operating system.
The instruction to switch to user mode is an example of a privilegedinstruction. Some other
examples include I/O control, timer management, andinterrupt management.
We can now see the life cycle of instruction execution in a computer system.Initial control is
within the operating system, where instructions are executedin kernel mode. When control is
given to a user application, the mode is set touser mode. Eventually, control is switched back to
the operating system via aninterrupt, a trap, or a system call.
When a system call is executed, it is treated by the hardware as a softwareinterrupt. Control
passes through the interrupt vector to a service routine inthe operating system, and the mode bit

10
is set to kernel mode. The systemcallservice routine is a part of the operating system. The kernel
examinesthe interrupting instruction to determine what system call has occurred; aparameter
indicates what type of service the user program is requesting.Additional information needed for
the request may be passed in registers,on the stack, or in memory (with pointers to the memory
locations passed inregisters). The kernel verifies that the parameters are correct and legal,
executesthe request, and returns control to the instruction following the system call.
Timer
We must ensure that the operating system maintains control over the CPU.We must prevent a
user program from getting stuck in an infinite loop or notcalling system services and never
returning control to the operating system.To accomplish this goal, we can use a timer. A timer
can be set to interruptthe computer after a specified period. The period may be fixed (for
example,1/60 second) or variable (for example, from 1 millisecond to 1 second). Avariable
timer is generally implemented by a fixed-rate clock and a counter.The operating system sets the
counter. Every time the clock ticks, the counteris decremented. When the counter reaches 0, an
interrupt occurs. For instance,a 10-bit counter with a 1-millisecond clock allows interrupts at
intervals from1 millisecond to 1,024 milliseconds, in steps of 1 millisecond.
Before turning over control to the user, the operating system ensuresthat the timer is set to
interrupt. If the timer interrupts, control transfersautomatically to the operating system, which
may treat the interrupt as a fatalerror or may give the program more time. Clearly, instructions
that modify thecontent of the timer are privileged.
Thus, we can use the timer to prevent a user program from running toolong. A simple technique
is to initialize a counter with the amount of time that aprogram is allowed to run. A program with
a 7-minute time limit, for example,would have its counter initialized to 420. Every second, the
timer interruptsand the counter is decremented by 1. As long as the counter is positive, controlis
returned to the user program. When the counter becomes negative, theoperating system
terminates the program for exceeding the assigned timelimit.

PROCESS MANAGEMENT
Aprogram in execution, is a process. A time-shared user programsuch as a compiler is a process.
A word-processing program being run by anindividual user on a PC is a process. A system task,
such as sending outputto a printer, can also be a process (or at least part of one). It is possibleto
provide system calls that allow processes to create subprocesses to executeconcurrently.

11
A process needs certain resources—including CPU time, memory, files,and I/O devices—to
accomplish its task. These resources are either given tothe process when it is created or allocated
to it while it is running. In additionto the various physical and logical resources that a process
obtains when it iscreated, various initialization data (input) may be passed along.
We emphasize that a program by itself is not a process; a program is a passiveentity, such as the
contents of a file stored on disk, whereas a process is an activeentity. A single-threaded process
has one program counter specifying the nextinstruction to execute. The CPU executes one
instruction of theprocess after another, until the process completes. Thus, although twoprocesses
may be associated with the same program, they are neverthelessconsidered two separate
execution sequences. A multithreaded process hasmultiple program counters, each pointing to
the next instruction to execute fora given thread.
A process is the unit of work in a system. Such a system consists of acollection of processes,
some of which are operating-system processes (thosethat execute system code) and the rest of
which are user processes (those thatexecute user code). All these processes can potentially
execute concurrently—by multiplexing the CPU among them on a single CPU, for example.The
operating system is responsible for the following activities in connectionwith process
management:
• Creating and deleting both user and system processes
• Suspending and resuming processes
• Providing mechanisms for process synchronization
• Providing mechanisms for process communication
• Providing mechanisms for deadlock handling

MEMORY MANAGEMENT
The main memory is central to the operationof a modern computer system. Main memory is a
large array of words or bytes,ranging in size from hundreds of thousands to billions. Each word
or byte hasits own address. Main memory is a repository of quickly accessible data sharedby the
CPU and I/O devices. The central processor reads instructions from mainmemory during the
instruction-fetch cycle and both reads and writes data frommain memory during the data-fetch
cycle.
The main memory is generally the only large storage device that the CPU is ableto address and
access directly. For example, for the CPU to process data fromdisk, those data must first be

12
transferred to main memory by CPU-generatedI/O calls. In the same way, instructions must be in
memory for the CPU toexecute them.
For a program to be executed, it must be mapped to absolute addresses andloaded into memory.
As the program executes, it accesses program instructionsand data from memory by generating
these absolute addresses. Eventually,the program terminates, its memory space is declared
available, and the nextprogram can be loaded and executed.
To improve both the utilization of the CPU and the speed of the computer'sresponse to its users,
general-purpose computers must keep several programsin memory, creating a need for memory
management.
The operating system is responsible for the following activities in connectionwith memory
management:
• Keeping track of which parts of memory are currently being used and bywhom
• Deciding which processes (or parts thereof) and data to move into and outof memory
• Allocating and de-allocating memory space as needed
STORAGE MANAGEMENT
To make the computer system convenient for users, the operating systemprovides a uniform,
logical view of information storage. The operating systemabstracts from the physical properties
of its storage devices to define a logicalstorage unit, the file. The operating system maps files
onto physical media andaccesses these files via the storage devices.
File-System Management
Computers can store information on several different types of physical media such as
magnetic disk, optical disk, and magnetic tape. Eachof these media has its own characteristics
and physical organization. Eachmedium is controlled by a device, such as a disk drive or tape
drive, thatalso has its own unique characteristics. These properties include accessspeed,capacity,
data-transfer rate, and access method (sequential or random).A file is a collection of related
information defined by its creator. Commonly,files represent programs and data. Data files
maybe numeric, alphabetic, alphanumeric, or binary. Files may be free-form (forexample, text
files), or they may be formatted rigidly (for example, fixed fields).
The operating system is responsible for the following activities in connectionwith file
management:
• Creating and deleting files
• Creating and deleting directories to organize files

13
• Supporting primitives for manipulating files and directories
• Mapping files onto secondary storage
• Backing up files on stable (nonvolatile) storage media
Mass-Storage Management
Because main memory is too small to accommodateall data and programs, and because the data
that it holds are lost when poweris lost, the computer system must provide secondary storage to
back up mainmemory. Most modern computer systems use disks as the principal on-linestorage
medium for both programs and data. Most programs—includingcompilers, assemblers, word
processors, editors, and formatters—are storedon a disk until loaded into memory and then use
the disk as both the sourceand destination of their processing. The operating system isresponsible
for the following activities in connection with disk management:
• Free-space management
• Storage allocation
• Disk scheduling
There are, however, many uses for storage that is slower and lower in costthan secondary
storage. Backups of diskdata, seldom-used data, and long-term archival storage are some
examples.Magnetic tape drives and their tapes and CD and DVD drives and platters aretypical
tertiary storage devices. The media (tapes and optical platters) varybetween WORM (write-
once, read-many-times) and RW (read-write) formats.
Caching
Information isnormally kept in some storage system such as main memory. As it is used,it is
copied into a faster storage system—the cache—on a temporary basis.When we need a particular
piece of information, we first check whether it isin the cache. If it is, we use the information
directly from the cache; if it is not,we use the information from the source, putting a copy in the
cache under theassumption that we will need it again soon.
Because caches have limited size, cache management is an importantdesign problem. Careful
selection of the cache size and of a replacementpolicy can result in greatly increased
performance. See Figure 1.9 for a storageperformance comparison in large workstations and
small servers that showsthe need for caching.

14
The movement of information between levels of a storage hierarchy, depending on the
hardware design and thecontrolling operating-system software. For instance, data transfer from
cacheto CPU and registers is usually a hardware function, with no operating-systemintervention.
In contrast, transfer of data from disk to memory is usuallycontrolled by the operating system.
In a hierarchical storage structure, the same data may appear in differentlevels of the storage
system. For example, suppose that an integer A that is tobe incremented by 1 is located in file B,
and file B resides on magnetic disk.The increment operation proceeds by first issuing an I/O
operation to copy thedisk block on which A resides to main memory. This operation is followed
bycopying A to the cache and to an internal register. Thus, the copy of A appearsin several
places: on the magnetic disk, in main memory, in the cache, and in aninternal register The Figure
1.10 shows this one. Once the increment takes place in the internalregister, the value of A differs
in the various storage systems. The value of Abecomes the same only after the new value of A is
written from the internalregister back to the magnetic disk.

15
I/O Systems
One of the purposes of an operating system is to hide the peculiarities of specifichardware
devices from the user. For example, in UNIX, the peculiarities of I/Odevices are hidden from the
bulk of the operating system itself by the I/Osubsystem. The I/O subsystem consists of several
components:
• A memory-management component that includes buffering, caching, andspooling
• A general device-driver interface
• Drivers for specific hardware devices
Only the device driver knows the peculiarities of the specific device to whichit is assigned.
PROTECTION AND SECURITY
If a computer system has multiple users and allows the concurrent executionof multiple
processes, then access to data must be regulated. For that purpose,mechanisms ensure that files,
memory segments, CPU, and other resources canbe operated on by only those processes that
have gained proper authorizationfrom the operating system. For example, memory-addressing
hardwareensures that a process can execute only within its own address space. Thetimer ensures
that no process can gain control of the CPU without eventuallyrelinquishing control. Device-
control registers are not accessible to users, sothe integrity of the various peripheral devices is
protected.
Protection, then, is any mechanism for controlling the access of processesor users to the
resources defined by a computer system.
Protection can improve reliability by detecting latent errors at the interfacesbetween component
subsystems. Early detection of interface errors can oftenprevent contamination of a healthy
subsystem by another subsystem thatis malfunctioning. An unprotected resource cannot defend
against use (ormisuse) by an unauthorized or incompetent user. A protection-oriented
systemprovides a means to distinguish between authorized and unauthorized usage.
A system can have adequate protection but still be prone to failure andallow inappropriate
access. Consider a user whose authentication informationis stolen. Her data could becopied or
deleted, even though file and memory protection are working. It isthe job of security to defend a
system from external and internal attacks. Suchattacks spread across a huge range and include
viruses and worms, denial-ofserviceattacks, identity theft, and theft of service. Prevention of
some of these attacks is consider an operatingsystemfunction on some systems, while others
leave the prevention to policyor additional software.

16
Protection and security require the system to be able to distinguish amongall its users. Most
operating systems maintain a list of user names andassociated user identifiers (user IDs). In
Windows NT parlance, this is a securityID (SID). These numerical IDs are unique, one per user.
When a user logs into the system, the authentication stage determines the appropriate user ID
forthe user. That user ID is associated with all of the user's processes and threads.
In some circumstances, we wish to distinguish among sets of users ratherthan individual users.
For example, the owner of a file on a UNIX system may beallowed to issue all operations on that
file, whereas a selected set of users mayonly be allowed to read the file. To accomplish this, we
need to define a groupname and the set of users belonging to that group. Group functionality
canbe implemented as a system-wide list of group names and group identifiers.

1.3 OPERATING-SYSTEM FUNCTIONS/SERVICES:


An operating system provides an environment for the execution of programs. It provides certain
services to programs and to the users of those programs. The specific services provided, of
course, differ from one operating system to another, but we can identify common classes. These
operating-system services are provided for the convenience of the programmer, to make the
programming task easier
One set of operating-system functions are helpful to the user.
• User interface. Almost all operating systems have a user interface (UI). This interface can take
several forms. One is a command-line interface (CLI), which uses text commands and a method
for entering them (say, a program to allow entering and editing of commands). Another is a batch
interface, in which commands and directives to control those commands are entered into files,
and those files are executed. Most commonly/ a graphical user interface (GUI) is used. Here, the
interface 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.
• 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 specific devices, special functions may be desired (such as recording to a CD or
DVD drive or blanking a CRT screen). For efficiency and protection, users usually cannot
control I/O devices directly. Therefore, the operating system must provide a means to do I/O.

17
• File-system manipulation. The file system is of particular interest. Obviously, 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. Finally, some programs include permissions
management to allow or deny access to files or directories based on file ownership.
• 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 or through message passing, in which packets of information are moved between
processes by the operating system.
• Error detection. The operating system needs to be constantly aware of possible errors. 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 tape, 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. Debugging facilities can greatly enhance the user's and programmer's
abilities to use the system efficiently.
Another set of operating-system functions exists not for helping the user but rather for ensuring
the efficient operation of the system itself. Systems with multiple users can gain efficiency by
sharing the computer resources among the users.
• Resource allocation. When there are multiple users or multiple jobs running at the same time,
resources must be allocated to each of {hem. Many different types of resources are managed by
the operating system. Some (such as CPU cycles, main memory, and file storage) may have
special allocation code, whereas others (such as I/O devices) may have much more general
request and release code.
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, modems,
USB storage drives, and other peripheral devices.
• Accounting. We want to keep track of which users use how much and what kinds of computer
resources. This record keeping may be used for accounting (so that users can be billed) or simply

18
for accumulating usage statistics. Usage statistics may be a valuable tool for researchers who
wish to reconfigure the system to improve computing services.
• Protection and security. The owners of information stored in a multiuser or networked
computer system may want to control use of that information. When several separate processes
execute concurrently, it should not be possible for one process to interfere with the others or with
the operating system itself. Protection involves ensuring that all access to system resources is
controlled.
Security of the system from outsiders is also important. Such security starts with requiring each
user to authenticate him or her to the system, usually by means of a password, to gain access to
system resources. It extends to defending external I/O devices, including modems and network
adapters, from invalid access attempts and to recording all such connections for detection of
break-ins.
If a system is to be protected and secure, precautions must be instituted throughout it. A chain is
only as strong as its weakest link.
1.4 Computing Environments
1. Introduction to Computing Environments
A computing environment refers to the combination of hardware, software, network
infrastructure, and services that provide a framework in which users can interact with a
computer system to run applications, access data, and perform computational tasks. In the
context of operating systems, the term "computing environment" typically refers to the
environment created by the OS that supports various types of computing, including
individual desktop systems, networked systems, and large-scale distributed systems.

Different computing environments vary in terms of their capabilities, complexity, and the
way they manage resources. Understanding these environments is critical for system
administrators, software developers, and end-users to optimize the use of computing
resources and select the appropriate environment for their needs.

2. Types of Computing Environments


Computing environments can be broadly categorized based on the scale, configuration,
and level of integration between hardware and software. The main categories include:

19
- Personal Computing Environment
- Multi-user and Time-sharing Environment
- Distributed Computing Environment
- Cloud Computing Environment
- Real-time Computing Environment
- Embedded Systems Environment

1. Personal Computing Environment


A Personal Computing Environment is typically associated with individual users and
their personal devices, such as laptops, desktops, or mobile phones. This environment is
designed for single-user interaction with the system, often running a single operating
system like Windows, macOS, or Linux.
- Characteristics:
- Single-user environment with dedicated access to resources.
- Operating systems like Windows, macOS, or Linux provide the interface.
- The user has complete control over the system's resources (CPU, memory, file system,
etc.).
- Supports personal applications such as word processors, web browsers, and media
players.
- Advantages:
- Simple setup and configuration.
- Direct control over applications and files.
- Local storage for data and programs.

-Disadvantages:
- Limited scalability for running large-scale applications.
- Typically not designed for collaboration or resource sharing.
Example:
A typical personal computing environment could be a Windows desktop running a web
browser, text editor, and media player, where the user has full control over their local
machine.

20
2. Multi-user and Time-sharing Environment
A Multi-user and Time-sharing Environment allows multiple users to access and share
the same system resources simultaneously. In this environment, the operating system
efficiently allocates resources to each user, typically through the use of time-sharing,
where the CPU time is divided into small slices and assigned to different users in a
rotating fashion.
- Characteristics:
- Time-sharing: Multiple users share the system, with each being allocated a small time
slice.
- Centralized resources managed by a single OS instance.
- Used in mainframe computers and minicomputers.
- Users interact with the system through terminals, often using command-line interfaces
or graphical user interfaces.
- Advantages:
- Resource optimization by allowing many users to share the same hardware.
- Easy system management and maintenance from a central point.
- Facilitates remote access for multiple users.
- Disadvantages:
- Performance degradation if too many users are connected simultaneously.
- Security concerns in managing user data and process isolation.
Example:
A UNIX-based multi-user environment, where many users can log in and run their
programs remotely via a terminal (using SSH), all using a shared set of system resources.
3. Distributed Computing Environment
In a Distributed Computing Environment, multiple independent computers (nodes) work
together over a network to perform a task. These nodes communicate with each other to
share resources and complete computational tasks, often appearing as a single unified
system to the user.
Characteristics:
- Networked Systems: Computers are connected via a network and can communicate
with each other.

21
- Distributed Resources: Resources such as storage, processing power, and memory are
distributed across multiple machines.
- Fault tolerance and scalability: Distributed systems are often designed to be fault-
tolerant and scalable, allowing them to handle failures and growing workloads.
- Advantages:
- High availability and fault tolerance, as failure of one node does not bring down the
entire system.
- Scalability, as more nodes can be added to meet growing demands.
- Load balancing, allowing tasks to be distributed among several machines.
- Disadvantages:
- Complexity in managing and coordinating the system.
- Potential performance bottlenecks in network communication.
- Increased security risks due to distributed nature and data sharing.
Example:
A cluster of computers running a distributed application where users are unaware of the
physical separation of resources, such as Apache Hadoop, which performs parallel data
processing across multiple nodes.
4. Cloud Computing Environment

Cloud Computing is a modern computing environment where users access and use
computing resources (such as servers, storage, databases, networking, software, etc.) over
the internet, typically hosted by third-party providers like Amazon Web Services (AWS),
Microsoft Azure, or Google Cloud.

- Characteristics:
- On-demand access: Resources are available on-demand and can be provisioned
dynamically.
- Resource Pooling: Resources are shared between multiple tenants, often in a multi-
tenant environment.
- Elasticity: The ability to scale resources up or down based on demand.
- Virtualization: Cloud services are typically built on top of virtualized resources,
allowing flexibility and efficient resource allocation.

22
Advantages:
- Cost-effective: Users pay only for the resources they use.
- Scalability: Resources can be quickly scaled up or down.
- Accessibility: Users can access cloud resources from anywhere with an internet
connection.
- Disadvantages:
- Dependence on an internet connection.
- Security and privacy concerns due to data being stored off-premises.
- Potential for vendor lock-in.
Example:
A user accessing a cloud-based application like Google Docs or running a machine
learning model on AWS EC2 instances, where computing power is provided by the cloud
rather than local hardware.
5. Real-Time Computing Environment
A Real-time Computing Environment is designed to meet strict timing constraints. In
these environments, the system must respond to inputs within a fixed period. Real-time
systems are used in applications where delays could lead to critical failures, such as in
embedded systems, automotive control, medical devices, and industrial systems.
- Characteristics:
- Deterministic: Operations must occur within specified time limits.
- Hard and Soft Real-Time Systems:
- Hard Real-Time: Missing a deadline is catastrophic (e.g., pacemaker).
- Soft Real-Time: Missing a deadline is undesirable but not critical (e.g., video
streaming).
- Priority Scheduling: Tasks are often assigned priorities based on their urgency.
- Advantages:
- Predictable system behavior and response time.
- Essential for time-critical applications.
- Disadvantages:
- Complex to design and implement due to strict timing constraints.
- Limited scalability due to the need to guarantee response times.

23
Example:
A flight control system in an aircraft, where real-time data processing and immediate
responses to inputs are necessary to ensure the safety and performance of the aircraft.

6. Embedded Systems Environment


Embedded Systems are specialized computing systems designed to perform specific
functions or tasks within larger systems. These systems are typically resource-
constrained, with limited CPU, memory, and storage capacity. They are found in
everyday devices like smartphones, smart home devices, automobiles, and medical
devices.

- Characteristics:
- Task-Specific: Designed to perform a specific function or set of functions.
- Limited Resources: Typically operate with limited CPU power, memory, and storage.
- Real-Time Operation: Many embedded systems operate in real-time environments,
requiring deterministic behavior.
- Low Power Consumption: Optimized for power efficiency.

- Advantages:
- High reliability and efficiency for specific tasks.
- Low cost and small form factor.
- Often operate without requiring user intervention.

- Disadvantages:
- Limited flexibility: Cannot be easily reprogrammed for different tasks.
- Difficulty in upgrading hardware.

Example:
A smart thermostat in a home automation system that continuously monitors temperature
and adjusts the heating or cooling based on preset conditions.

24
- Personal Computing Environments: Single-user systems like desktops and laptops.
- Multi-user and Time-sharing Environments: Systems where multiple users share
resources, often found in mainframes and minicomputers.
- Distributed Computing Environments: Multiple computers work together to solve a
problem, providing scalability and fault tolerance.
- Cloud Computing Environments: On-demand, virtualized resources provided over the
internet.
- Real-time Computing Environments: Systems where timing is crucial, such as in
embedded systems and control systems.
- Embedded Systems Environments: Resource-constrained systems designed for specific
tasks.

Understanding different computing environments is essential for selecting the right


platform for a given application. From personal computers to complex cloud and
distributed systems, each environment has its unique characteristics that influence
performance, scalability, and usability. As technology advances, these environments are
becoming more interconnected and specialized, driving innovation in computing.

1.5 Free and Open-Source Operating Systems


Open-Source OS: These operating systems have source code that is publicly available, allowing
users to modify and distribute the software.

 Examples: Linux, FreeBSD, Android

Advantages:

 Customization: Users can modify the source code to fit specific needs.
 Cost: Open-source OSs are typically free to use.
 Community Support: Large online communities offer support, resources, and updates.

Disadvantages:

 Complexity: Open-source OSs can be complex to install and configure.


 Compatibility: Some hardware and software may not be supported.

25
SYSTEM STRUCTURES

An OS provides services to applications and users through several key system structures:

 Operating System Services: These are the core functions provided by the OS, such as
process scheduling, memory management, file system management, etc.
 User and Operating-System Interface: This is the interface that allows users to interact
with the OS (e.g., command-line interface or graphical user interface).
 System Calls: These are the means by which programs request services from the OS.
Examples include file operations (open, read, write), process control (fork, exit), and
communication (send, receive).
 Types of System Calls:
o Process Control: fork(), exit(), wait()
o File Management: open(), close(), read(), write()
o Device Management: ioctl(), read(), write()
o Information Maintenance: getpid(), gettimeofday()

1.6 Operating System Services


1. Introduction to Operating System Services
In an operating system (OS), services are essential programs and functions that provide users,
applications, and system processes with access to hardware resources and system-level
functionalities. An operating system manages a computer's hardware and software resources,
and provides a set of services to both users and applications to facilitate smooth operation.
Operating system services act as a bridge between user applications and the underlying
hardware. These services are typically implemented as system calls, which allow user
programs to request the OS to perform tasks like memory management, process management,
file handling, and device control.

The core functionality of an OS depends on these services, which make it possible for users
and programs to interact with the system in a controlled, efficient, and secure manner.

2. Key Types of Operating System Services

Operating system services can be broadly categorized into several types based on their
functionality. The primary categories are:

26
- Process Management Services
- Memory Management Services
- File System Services
- Device Management Services
- Security and Access Control Services
- Networking Services
- Error Handling and Debugging Services

Each of these services provides essential functionality for different parts of the system to
operate efficiently and securely.
1. Process Management Services

Process management services handle the creation, scheduling, execution, and termination of
processes. Processes are instances of programs in execution, and managing them effectively
is crucial for multitasking, process synchronization, and resource allocation.

- Process Creation: OS services allow programs to create new processes (e.g., fork in Unix-
like OS).
- Process Scheduling: The OS schedules processes to run based on priority and resource
availability.
- Process Synchronization: The OS provides mechanisms like semaphores and mutexes to
prevent conflicts when multiple processes access shared resources.
- Process Termination: OS services ensure processes are safely terminated and that resources
are freed.

Example:
When a user runs a command in a terminal, the operating system initiates a new process to
execute the program associated with the command. This is done through the fork() and exec()
system calls in Unix-like systems.

---

27
2. Memory Management Services
Memory management services are responsible for allocating and deallocating memory
resources to processes and applications. Efficient memory management ensures that
programs use memory resources without conflicts, and that the system operates within its
physical memory limits.

- Memory Allocation: The OS allocates memory to processes when they are created and
ensures that processes cannot access each other’s memory space.
- Virtual Memory: This service enables processes to use more memory than physically
available by swapping data in and out of secondary storage (e.g., the hard drive).
- Memory Protection: The OS prevents processes from accessing or modifying memory that
belongs to other processes, ensuring data integrity and security.
- Memory Deallocation: After a process finishes execution, the OS releases the memory it
used, making it available for other processes.

Example:
When a program is executed, the OS allocates a portion of the system’s memory to the
program's variables and data. The program operates within this allocated memory space, and
the OS ensures that other programs do not interfere.
3. File System Services
File system services are responsible for managing files and directories, including reading and
writing data, organizing files, and managing access permissions. These services allow
applications and users to store, retrieve, and manipulate data on secondary storage devices
like hard drives and SSDs.

- File Creation and Deletion: The OS provides services to create new files and delete existing
ones.
- File Reading and Writing: OS services handle the reading and writing of file contents,
ensuring data is correctly stored and retrieved.
- Directory Management: Directories are used to organize files. OS services allow users to
create, delete, and navigate directories.

28
- File Access Control: The OS manages permissions for files (read, write, execute) to ensure
that only authorized users can access files.

Example:
In a Linux system, the open(), read(), and write() system calls are used by programs to
interact with files. The OS handles these requests and ensures that files are stored correctly in
the file system.

4. Device Management Services


Device management services handle the operation of hardware devices such as keyboards,
mice, printers, disks, and network interfaces. The OS abstracts hardware details and provides
a standard interface for devices to interact with programs.

- Device Drivers: OS provides specialized software (drivers) to interface with specific


hardware devices. These drivers convert the OS’s generic commands into device-specific
commands.
- Device Access: The OS provides services to allow programs to access input and output
devices, like reading data from a keyboard or sending data to a printer.
- Device Scheduling: For devices like hard drives and printers, the OS schedules access to
ensure efficient use of resources and to minimize delays.

Example:
When a user prints a document, the OS uses device management services to interact with the
printer, sending the print data through the corresponding device driver.

5. Security and Access Control Services


Operating system services also provide mechanisms for securing system resources, ensuring
data privacy, and controlling access to system resources. These services protect the system
from unauthorized access and ensure users’ and programs’ data is handled securely.

- User Authentication: The OS provides services to verify user identity, such as


username/password authentication, biometric authentication, and multi-factor authentication.

29
- Access Control: The OS enforces policies on who can access specific files, directories, and
devices, typically using file permissions and access control lists (ACLs).
- Encryption: The OS can provide services for encrypting files and communications to
protect sensitive data.
- Audit and Logging: The OS logs system activity to track user actions and detect security
breaches.

Example:
In Linux, chmod is used to change file permissions, while chown is used to change file
ownership, allowing the OS to control access to files based on user roles.

6. Networking Services
Networking services are responsible for enabling communication between different
computers over local or wide-area networks. The OS provides an abstraction layer for
networking, allowing programs to send and receive data over the network.

- Socket Programming: OS services provide sockets to allow programs to send and receive
data through TCP/IP or other communication protocols.
- Network Communication: The OS handles the routing and transmission of data packets
between systems, managing protocols such as TCP, UDP, and IP.
- Network Configuration: OS provides tools for configuring network interfaces, assigning IP
addresses, and managing DNS settings.

Example:
When a user accesses a website in a browser, the OS uses networking services to handle the
HTTP requests, which are routed through the network using TCP/IP.

7. Error Handling and Debugging Services


Error handling and debugging services assist in detecting, reporting, and resolving system
issues. These services help maintain system stability and allow developers to troubleshoot
problems.

30
- Error Detection: The OS detects errors such as memory access violations, file system
corruption, or invalid input/output operations.
- Error Reporting: OS provides mechanisms for reporting errors to the user or to system
administrators.
- Debugging Tools: The OS may provide utilities like gdb for debugging programs and
identifying errors in program execution.

Example:
When a program crashes due to a segmentation fault, the OS generates an error message, logs
the error, and may create a core dump file for debugging purposes.
Operating system services are the essential components that enable the smooth functioning of
an OS by providing critical functionalities that interact with hardware, manage resources, and
ensure security. These services are accessed via system calls and APIs, enabling user
applications and system processes to utilize hardware resources without directly interacting
with the hardware itself.

- Process Management Services: Handle the creation, scheduling, and termination of


processes.
- Memory Management Services: Manage the allocation and protection of memory.
- File System Services: Provide operations for file handling and directory management.
- Device Management Services: Manage input/output devices and their communication with
the system.
- Security Services: Enforce user authentication, access control, and data protection.
- Networking Services: Facilitate communication over networks.
- Error Handling and Debugging: Detect, report, and resolve system errors.

Understanding these services is crucial for both system administrators and software
developers to create efficient, secure, and reliable systems.

Operating system services provide the backbone for managing hardware resources, ensuring
system stability, and facilitating user and program interaction. These services allow the OS to
manage processes, memory, files, devices, and security efficiently. By abstracting the

31
complexities of hardware management, operating systems make it easier for users and
applications to perform tasks without having to manage low-level hardware details directly.

1.7 User and Operating-System Interface


1. Introduction to User and Operating-System Interface
The User and Operating-System Interface (UOI) refers to the means by which a user
interacts with the operating system (OS). The interface is critical for the OS to fulfill
its role of managing hardware resources and providing an environment where users
can run applications. This interface allows users to issue commands, request system
services, and interact with the underlying hardware without needing to know the
intricate details of hardware management.
The OS provides an abstraction layer between the user and the system's hardware,
allowing users to interact with the system efficiently and effectively. The interface
may be command-line-based, graphical, or a combination of both, depending on the
nature of the operating system and the user’s needs.

2. Types of User and Operating-System Interfaces


The two main types of user interfaces that allow interaction between users and the OS
are:

1. Command-Line Interface (CLI)


2. Graphical User Interface (GUI)
Both interfaces offer different user experiences and are designed for specific kinds of
users or usage scenarios.

1. Command-Line Interface (CLI)


A Command-Line Interface (CLI) allows users to interact with the operating system
by typing commands into a text-based terminal or console. The user types commands
that are executed by the OS, and the output is displayed as text. This type of interface
is often used in systems where efficiency and control over the system are critical.

32
- Characteristics of CLI:
- Text-based: Users type commands into a terminal window.
- Powerful and Flexible: CLI provides direct access to system commands and tools.
- Minimal Resource Usage: CLI environments consume minimal system resources
compared to GUI-based systems.
- Scripting and Automation: CLI supports scripting (e.g., Bash scripts), allowing
users to automate repetitive tasks.
- No Mouse: The user navigates the system entirely through the keyboard.
- Steeper Learning Curve: CLI requires users to remember commands, syntax, and
options.
- Advantages:
- Efficiency: For advanced users, CLI can be faster and more efficient for
performing system tasks.
- Automation: Commands can be written into scripts to automate complex
sequences of operations.
- Powerful System Control: Allows direct access to system utilities and services.

- Disadvantages:
- Steep Learning Curve: New users might find it challenging to remember
commands and their syntax.
- Limited Visual Feedback: CLI is text-based, which can make it harder for users to
interpret complex data.
Example:
In Linux, commands like `ls` (list directory contents), `cp` (copy files), and `rm`
(remove files) are all executed via the CLI, and their output is displayed in text form.

2. Graphical User Interface (GUI)


A Graphical User Interface (GUI) is a more intuitive and user-friendly interface that
allows users to interact with the operating system and applications using graphical
elements like windows, icons, buttons, and menus.

33
- Characteristics of GUI:
- Visual Elements: Includes windows, icons, buttons, menus, and other visual
elements.
- Point-and-Click Interaction: Users interact with the system using a mouse or
touchpad to point, click, and drag objects on the screen.
- User-friendly: Designed for ease of use, even for people with limited technical
expertise.
- Multi-tasking: GUI allows users to interact with multiple applications at once,
using overlapping windows or tabs.

- Advantages:
- Ease of Use: Suitable for beginners and casual users because of its intuitive design.
- Interactive: Provides a more engaging and visually informative experience.
- Accessibility: GUI is accessible to users with limited technical knowledge.

- Disadvantages:
- Resource Heavy: GUIs consume more system resources (CPU, memory, etc.)
compared to CLIs.
- Less Efficient for Experts: Power users may find the point-and-click interface
slower for certain tasks that are quick with a command-line interface.

Example:
In Windows, users interact with the OS through a graphical interface where they click
on Start Menu, File Explorer, and Control Panel to manage files, settings, and system
operations.

3. System Calls: The Link Between User and Operating-System Interface


A System Call is the primary mechanism by which a program requests a service from
the operating system. System calls provide a controlled interface for user-level
applications to access system resources such as memory, I/O devices, and files. The
OS provides a set of predefined system calls, each corresponding to a service or
operation that can be performed by the system.

34
System Call Categories:
- Process Control: Services related to process management, such as process creation,
termination, scheduling, etc. Examples: `fork()`, `exec()`, `wait()`, `exit()`.
- File Management: Services related to creating, deleting, reading, writing, and
managing files and directories. Examples: `open()`, `read()`, `write()`, `close()`,
`mkdir()`, `unlink()`.
- Device Management: Services that allow processes to interact with hardware
devices, such as reading from and writing to devices. Examples: `ioctl()`, `read()`,
`write()`.
- Memory Management: Services for allocating, deallocating, and managing memory.
Examples: `malloc()`, `free()`, `sbrk()`.
- Information Maintenance: Services related to system information, such as time,
process states, etc. Examples: `getpid()`, `gettimeofday()`.
- Communication: Services for inter-process communication (IPC) such as pipes,
message queues, and shared memory. Examples: `pipe()`, `shmget()`, `msgsnd()`,
`msgrcv()`.
When a user invokes a system call, the following steps occur:
1. User space to Kernel space transition: The user request (command) is passed to the
kernel through a system call.
2. Execution: The OS processes the request by executing the appropriate function.
3. Kernel to User space transition: After the request is executed, the result is sent
back to the user application.
Example:
In Linux, a user program requesting to read from a file would use the `read()` system
call. This system call sends the request to the OS kernel, which then interacts with the
file system to retrieve the requested data and return it to the program.
4. User Interfaces and Shells
While the user interface refers to the interaction model between the user and the OS,
the shell is an interface that interprets user commands and passes them to the
operating system. The shell can be either command-line-based or graphical.

35
- Shell: A program that provides an interface for users to interact with the OS. It reads
commands from the user, interprets them, and passes them to the OS as system calls.
- Bash Shell: In Linux/Unix systems, the Bash shell is a command-line interface that
accepts text-based commands and executes them. It provides advanced features such
as scripting, input/output redirection, and piping.
- PowerShell: In Windows, PowerShell is a shell that provides both command-line
and scripting functionality, allowing users to automate tasks and manage system
resources.
- Graphical Shells: In GUI environments, the shell provides a visual interface for the
user. Examples include Windows Explorer (in Windows) and GNOME or KDE (in
Linux environments), which allow users to manage files and system settings visually.
5. User Interface Abstraction and Multi-layered Interaction
An essential feature of modern OS is the abstraction layer that separates users and
applications from the underlying hardware. This abstraction ensures that users
interact with the OS without worrying about low-level details.
- Abstraction Layers:
- Application Layer: The topmost layer where user applications interact with the OS.
- System Call Interface (SCI): The interface between user programs and the kernel.
It exposes system calls to user applications.
- Kernel Layer: The core part of the OS that interacts directly with the hardware.
- Multi-layered Interaction: Most modern operating systems offer multiple ways for
users to interact, which may include:
- CLI for advanced users.
- GUI for general-purpose interactions.
- Touch interfaces for mobile and tablet devices.

- User and Operating-System Interface (UOI) is the medium through which users
interact with the OS, enabling them to request services, run applications, and access
system resources.
- The CLI is text-based, fast, and powerful but has a steeper learning curve.
- The GUI is visually intuitive and accessible but consumes more resources.

36
- System Calls are the key mechanism through which user programs communicate
with the OS, allowing users to perform system-level operations securely and
efficiently.
- The shell interprets user commands and provides a layer between the user and the
OS.
The User and Operating-System Interface serves as the bridge between the user and
the operating system, offering several ways to interact with the system. Whether
through text-based commands or graphical representations, the OS must efficiently
handle user requests while abstracting away the complexity of managing hardware
resources. The choice between a CLI, GUI, or a combination of both depends on the
user’s needs and the specific tasks at hand.
1.8 System call:
In computing, a system call is the programmatic way in which a computer program requests
a service from the kernel of the operating system it is executed on. This may include
hardware-related services (for example, accessing a hard disk drive), creation and execution
of new processes, and communication with integral kernel services such as process
scheduling. System calls provide an essential interface between a process and the operating
system.

37
System calls provide the means for a user program to ask the operating system to perform tasks
reserved for the operating system on the user program's behalf. A system call is invoked in a
variety of ways, depending on the functionality provided by the underlying processor. In all
forms, it is the method used by a process to request action by the operating system.

System calls can be grouped roughly into five major categories:


o process control
o file manipulation
o device manipulation
o information maintenance
o communications
The following are different sub categories of system calls:
• Process control
 end, abort
 load, execute
 create process, terminate process
 get process attributes, set process attributes
 wait for time
 wait event, signal event o allocate and free memory

• File management
 create file, delete file
 open, close
 read, write, reposition
 get file attributes, set file attributes
• Device management
 request device, release device
 read, write, reposition
 get device attributes, set device attributes
 logically attach or detach devices
• Information maintenance

38
 get time or date, set time or date
 get system data, set system data
 get process, file, or device attributes
 set process, file, or device attributes
• Communications
 create, delete communication connection
 send, receive messages
 transfer status information
 attach or detach remote devices

Process Control
A running program needs to be able to halt its execution either normally (end) or abnormally
(abort). If a system call is made to terminate the currently running program abnormally, or if the
program runs into a problem and causes an error trap, a dump of memory is sometimes taken and
an error message generated. The dump is written to disk and may be examined by a debugger—a
system program designed to aid the programmer in finding and correcting bugs-—to determine
the cause of the problem.
Under either normal or abnormal circumstances, the operating system must transfer control to the
invoking command interpreter. The command interpreter then reads the next command. In an
interactive system, the command interpreter simply continues with the next command; it is
assumed that the user will issue an appropriate command to respond to any error.
File Management
There are several common system calls dealing with files, we first need to be able to create and
delete files. Either system call requires the name of the file and perhaps some of the file's
attributes.
Once the file is created, we need to open it and to use it. We may also read, write, or reposition
(rewinding or skipping to the end of the file, for example). Finally, we need to close the file,
indicating that we are no longer using it.
We may need these same sets of operations for directories if we have a directory structure for
organizing files in the file system. In addition, for either files or directories, we need to be able to
determine the values of various attributes and perhaps to reset them if necessary.

39
File attributes include the file name, a file type, protection codes, accounting information, and so
on. At least two system calls, get file attribute and set file attribute, are required for this function.
Device Management
A process may need several resources to execute—main memory, disk drives, access to files, and
so on. If the resources are available, they can be granted, and control can be returned to the user
process. Otherwise, the process will have to wait until sufficient resources are available.
The various resources controlled by the operating system can be thought of as devices. Some of
these devices are physical devices (for example, tapes), while others can be thought of as abstract
or virtual devices (for example, files).
Information Maintenance
Many system calls exist simply for the purpose of transferring information between the user
program and the operating system. For example, most systems have a system call to return the
current time and date. Other system calls may return information about the system, such as the
number of current users, the version number of the operating system, the amount of free memory
or disk space, and so on.
In addition, the operating system keeps information about all its processes, and system calls are
used to access this information. Generally, calls are also used to reset the process information
(get process attribute s and s e t process attributes)
Communication
There are two common models of inter-process communication:
The message passing model
The shared-memory model.
In the message-passing model, the communicating processes exchange messages with one
another to transfer information. Messages can be exchanged between the processes either
directly or indirectly through a common mailbox. Before communication can take place, a
connection must be opened. The name of the other communicator must be known, be it another
process on the same system or a process on another computer connected by a communications
network.
In the shared-memory model, processes use shared memory creates and shared memory
attaches system calls to create and gain access to regions of memory owned by other processes.
Normally the operating system tries to prevent one process from accessing another process's
memory.

40
Shared memory requires that two or more processes agree to remove this restriction. They can
then exchange information by reading and writing data in the shared areas. Both of these models
are common in operating systems, and most systems implement both.
Message passing is useful for exchanging smaller amounts of data, because no conflicts need be
avoided. It is also easier to implement than is shared memory for inter computer communication.
Shared memory allows maximum speed and convenience of communication, since it can be done
at memory speeds when it takes place within a computer.
1.9 Types of system Calls

1. Introduction to System Calls


A system call is a mechanism used by applications to request services from the operating
system (OS) kernel. System calls provide the interface between a running program (user
space) and the kernel (core of the operating system). They are essential for performing tasks
such as creating processes, handling I/O operations, managing memory, and performing
network communication.

2. Purpose of System Calls


-Abstraction: System calls abstract the complexity of hardware, providing a simpler interface
for applications to interact with the system.
- Security and Protection: The OS kernel controls access to system resources, ensuring that
applications cannot directly access or modify critical resources.
- Resource Management: System calls are used to manage hardware resources such as CPU,
memory, storage, and I/O devices.
- Communication: They facilitate communication between processes (Inter-process
communication).

3. Types of System Calls


System calls can be categorized based on their functionality. Here are the primary categories:
1. Process Control System Calls
These system calls are related to the creation, management, and termination of processes.
- fork(): Creates a new process by duplicating the calling process. The new process is called
the child process.

41
- exec(): Replaces the current process image with a new program. This is commonly used
after a `fork()` to load a new program.
- exit(): Terminates the current process and returns a status code to the operating system.
- wait(): Makes the parent process wait until its child process terminates. This is used for
process synchronization.
- getpid(): Returns the Process ID (PID) of the calling process.
- getppid(): Returns the Parent Process ID (PPID).
- kill(): Sends a signal to a process, typically used to terminate or pause the process.

Example:
pid_t pid = fork();
if (pid == 0) {
// Child process code
execvp("ls", (char *[]){"ls", NULL});
} else {
// Parent process waits for child
wait(NULL);
}

2. File Management System Calls


These system calls allow for file creation, manipulation, and deletion.
- open(): Opens a file for reading or writing. It returns a file descriptor.
- read(): Reads data from an open file into a buffer.
- write(): Writes data from a buffer to an open file.
- close(): Closes an open file descriptor.
- lseek(): Moves the file pointer to a specific location in a file, allowing random access.
- unlink(): Deletes a file from the file system.
- stat(): Retrieves information about a file (e.g., file size, permissions, timestamps).
- chmod(): Changes the permissions of a file.
- rename(): Renames or moves a file.

42
Example:
int fd = open("myfile.txt", O_RDONLY);
if (fd == -1) {
perror("File open failed");
}
char buffer[100];
int bytesRead = read(fd, buffer, sizeof(buffer));
close(fd);

3. Memory Management System Calls


These system calls are related to managing memory allocation and deallocation.
- brk(): Expands or shrinks the data segment of a process, adjusting the program's heap.
- sbrk(): Increases or decreases the program’s data space (heap). This is considered outdated
and replaced by modern memory management techniques.
- mmap(): Maps files or devices into memory, allowing processes to access the file content
directly in memory.
- munmap(): Unmaps memory regions previously mapped by `mmap()`.

Example:
void *ptr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE |
MAP_ANONYMOUS, -1, 0);
if (ptr == MAP_FAILED) {
perror("Memory mapping failed");
}
munmap(ptr, 4096);

4. I/O Control System Calls

These system calls provide mechanisms to interact with devices, read data, and send data to
external devices like disks, network interfaces, etc.

43
- ioctl(): Performs device-specific input/output operations. For example, changing the
settings of a terminal or controlling the hardware directly.
- read(): Reads data from an input device or file.
- write(): Writes data to an output device or file.
- select(): Monitors multiple file descriptors to see if they are ready for reading or writing.

Example:
int fd = open("/dev/ttyS0", O_RDWR);
if (fd == -1) {
perror("Failed to open serial port");
}
ioctl(fd, TIOCMGET, &status); // Get modem status
close(fd);

5. Communication System Calls

These system calls are used for communication between processes.


- pipe(): Creates a unidirectional data channel between two processes for inter-process
communication (IPC).
- msgget(), msgsnd(), msgrcv(): Used for message queue management.
- semget(), semop(): Used to manage semaphores for process synchronization.
- shmget(), shmat(): Used for shared memory management.

int fd[2];
pipe(fd); // Creates a pipe (fd[0] - read, fd[1] - write)
write(fd[1], "Hello, world!", 13);
char buffer[13];
read(fd[0], buffer, 13);
6. Information Maintenance System Calls
These system calls provide information about the system or current process.
- getpid(): Returns the Process ID of the calling process.
- getppid(): Returns the Parent Process ID.

44
- getuid(): Returns the user ID of the calling process.
- getgid(): Returns the group ID of the calling process.
- sysinfo(): Provides system information such as memory usage, load average, etc.
- times(): Returns process times (user and system time) for the calling process.

Example:

pid_t pid = getpid();


printf("Current process ID: %d\n", pid);

4. Categorization of System Calls

System calls can also be categorized based on how they are invoked by the program:

- Library Calls: Standard library functions that internally invoke system calls. For example,
`fopen()` in C is a library call that may invoke `open()` system call.
- Direct System Calls: Direct invocations of system calls, typically using low-level system
interfaces.

5. System Call Interfaces

To use system calls, an application interacts with system call interfaces (such as standard
libraries or wrappers). These interfaces translate the user-level requests into system-level
calls. For example, in C, the standard library (`glibc`) provides wrapper functions like
`read()` and `write()`, which in turn invoke the appropriate system call.

- System calls provide a controlled interface between user-level applications and the
operating system.
- Different types of system calls manage processes, files, memory, I/O devices,
communication, and system information.
- System calls are essential for enabling application-level interaction with hardware,
performing file operations, memory management, and inter-process communication.

45
Understanding system calls is crucial for system-level programming, as they allow
developers to interact with the underlying OS services directly. Mastery of these concepts is
key for creating efficient and secure applications that leverage OS capabilities.
1.10 System Programs
1. Introduction to System Programs

System programs (also known as utility programs) are a set of programs that provide
essential services to users and applications in an operating system. While system calls
directly interact with the OS kernel to manage hardware and resources, system programs are
built on top of the system call interface and provide higher-level functionalities, making the
OS more usable for users and applications.

System programs perform a variety of tasks like process management, file management,
system diagnostics, text editing, compiling, debugging, and more. They provide the user with
tools to interact with the operating system efficiently and aid in the development and
execution of user applications.

2. Types of System Programs

System programs can be classified based on their functionality. Below is an overview of the
various types of system programs:

1. File Management Programs

File management system programs are responsible for tasks related to file handling,
including creating, reading, writing, deleting, and manipulating files and directories. Some of
these programs include:

- File Editors: Programs like vi, nano, and emacs that allow users to create and edit text files.
- File Browsers: Tools like Explorer in Windows or Nautilus in Linux that provide a
graphical interface to browse and manage files and directories.
- Backup Utilities: Programs like tar and rsync that are used to back up files and directories
to prevent data loss.
- File Compression Tools: Programs like gzip, zip, and tar that are used to compress and
decompress files, saving storage space.
- Disk Management Tools: Programs like chkdsk and fsck that check the integrity of the file
system and repair damaged file systems.

Example:
bash
tar -czf backup.tar.gz /home/user/documents
This command uses the `tar` program to create a compressed archive of files.

46
2. Process Management Programs

Process management system programs allow users to control and monitor running processes,
including process creation, termination, scheduling, and interaction. Key programs include:

- Process Control Programs:


- ps: Displays information about running processes (e.g., `ps aux` shows all running
processes).
- top: Displays a dynamic view of running processes, including CPU and memory usage.
- kill: Sends signals to processes (e.g., `kill -9 <PID>` terminates a process).
- nice/renice: Adjusts the priority of a process to control CPU scheduling.

Example:
bash
ps aux | grep "httpd"

This command lists all processes related to the HTTP server.

3. System Information Programs

These programs provide information about system resources, hardware configuration, and
status. They are important for system diagnostics and performance monitoring.

- CPU Information:
- lscpu: Displays detailed information about the CPU architecture.
- top: Displays CPU utilization in real time.
- Memory Information:
- free: Displays information about system memory (RAM and swap).
- vmstat: Provides information about system processes, memory, paging, and block I/O.
- Disk and I/O Information:
- df: Displays disk space usage on mounted filesystems.
- du: Shows the disk usage of files and directories.
- iotop: Monitors I/O usage by processes in real time.

Example:
bash
free -h

This command displays system memory usage in a human-readable format.

4. User Interface Programs

User interface programs allow users to interact with the operating system in a user-friendly
manner. These can either be command-line-based or graphical.

47
- Shell Programs:
- bash: A widely used shell program for command-line interaction.
- zsh: An alternative to bash, offering additional features and customizability.
- Graphical User Interface (GUI) Programs: These include programs like X Window System
and GNOME or KDE desktop environments, which provide a graphical interface for
interacting with the operating system.

Example:
bash
gnome-terminal

This command opens the GNOME terminal, providing the user with a shell interface.

5. Programming and Development Tools

These system programs help developers write, compile, and debug code. They typically
include compilers, debuggers, and other tools necessary for software development.

- Compilers:
- gcc: The GNU C Compiler used to compile C programs.
- g++: The GNU C++ Compiler for compiling C++ programs.
- javac: The Java compiler for compiling Java programs.
- Debuggers:
- gdb: The GNU Debugger, used to debug C/C++ programs.
- strace: A diagnostic tool that traces system calls and signals.
- Build Tools:
- make: Automates the process of building executable programs and libraries from source
code.
- cmake: A build system generator that uses configuration files to create makefiles for
building programs.

Example:
bash
gcc -o hello hello.c

This command compiles the C program `hello.c` and generates an executable named `hello`.

6. Networking Programs

Networking system programs help manage and troubleshoot network connections, transfer
data, and perform diagnostics. Common networking programs include:

- ping: A tool for testing network connectivity to a remote host.


- ifconfig/ip: Used to configure and display network interface settings.

48
- netstat: Displays network connections, routing tables, and interface statistics.
- wget/curl: Programs for downloading files from the internet.
- ssh: A tool for securely connecting to remote systems.

Example:
bash
ping google.com

This command checks whether the system can reach Google servers over the network.

7. Security Programs
Security system programs provide various mechanisms to secure the system, such as
encryption, user authentication, and access control. Key programs include:
- chmod: Changes the permissions of files or directories.
- chown: Changes the ownership of files or directories.
- passwd: Allows users to change their password.
- gpg: The GNU Privacy Guard, used for encryption and signing data.
Example:
bash
chmod 755 myscript.sh

This command changes the permissions of `myscript.sh` so that the owner can
read/write/execute, and others can read/execute.

3. Common Features of System Programs

System programs share several common features, such as:

-Efficiency: They are designed to be fast and perform specific tasks with minimal resource
overhead.
- Security: Many system programs include access controls, auditing, and logging to ensure
that system operations are secure.
- Automation: Some system programs, such as build tools (`make`) and backup utilities, are
designed to automate repetitive tasks for users.
- Portability: Many system programs are written in languages like C and Python, which allow
them to be used on various hardware platforms and operating systems.
- System programs provide crucial services to users and applications, helping them interact
with the operating system and manage resources efficiently.
- They include file management tools, process management utilities, development tools,
system information programs, and networking programs, among others.
- Understanding system programs is vital for both system administrators and developers, as
they form the foundation of user interaction with the operating system.

System programs are an integral part of any operating system, making it functional, user-
friendly, and efficient. By understanding these system programs and their operations, users
can effectively manage their systems, troubleshoot problems, and develop software that
interacts well with the underlying OS.

49
1.11 Operating system design and Implementation

The design and implementation of an OS involves several steps:

 Design: Determining the structure of the operating system, including process


management, memory management, file system design, and system security.
 Implementation: Writing the code to bring the design to life, involving programming
languages like C or assembly.
 Modularity: Modern operating systems are built in a modular way, where different
components (e.g., file systems, device drivers) are developed independently.
 Booting an Operating System: The process of loading the OS into memory from a
storage device (e.g., hard disk or SSD) to start the system.

1.12 Operating system Structure


2.  Monolithic Structure: The OS is a single large program, where all components
interact directly.
3.  Microkernel Structure: The OS is divided into smaller modules that run separately.
The microkernel provides only the essential services.
4.  Layered Structure: The OS is organized into layers, each of which provides services
to the layers above it.
5.  Client-Server Model: The OS is divided into client and server components that
communicate over a network.

1.13 Building and Booting an Operating System


 Booting: The process begins with the BIOS (Basic Input/Output System) or UEFI (Unified
Extensible Firmware Interface) that initializes hardware and loads the OS kernel into memory.
 Boot Loader: A small program that loads the OS kernel into memory and starts its
execution. Examples include GRUB (for Linux) and NTLDR (for Windows).
1.14 Operating System Debugging

Debugging is the process of identifying and resolving errors or bugs in the operating system.
Some debugging techniques include:

 Kernel Debugging: Involves debugging the OS kernel to resolve low-level issues.


 System Call Tracing: Monitoring the system calls made by programs to detect abnormal
behavior.
 Memory Dump Analysis: Inspecting memory dumps to understand the state of the
system during a crash.

50

You might also like