Operating System
Operating System
Operating System lies in the category of system software. It basically manages all the
resources of the computer. An operating system acts as an interface between the software
and different parts of the computer or the computer hardware. The operating system is
designed in such a way that it can manage the overall resources and operations of the
computer.
Operating System is a fully integrated set of specialized programs that handle all the
operations of the computer. It controls and monitors the execution of all other programs that
reside in the computer, which also includes application programs and other system software
of the computer. Examples of Operating Systems are Windows, Linux, Mac OS, etc.
The salient points about the above figure displaying Computer System Organisation is
−The I/O devices and the CPU both execute concurrently. Some of the processes are
scheduled for the CPU and at the same time, some are undergoing input/output
operations.
There are multiple device controllers, each in charge of a particular device such as
keyboard, mouse, printer etc.There is buffer available for each of the devices. The input
and output data can be stored in these buffers.The data is moved from memory to the
respective device buffers by the CPU for I/O operations and then this data is moved
back from the buffers to memory.The device controllers use an interrupt to inform the
CPU that I/O operation is completed.
STORAGE STRUCTURE
This arrangement is usually not possible for the following two reasons:
1. Main memory is usually too small to store all needed programs and data
permanently.
2. Main memory is a volatile storage device that loses its contents when power is
turned off or otherwise lost.
It does not loses its contents when the power is removed. It holds all the data when the
power is removed.
The storage systems above the Electronic disk are Volatile, where as those below are
Non-Volatile.
An Electronic disk can be either designed to be either Volatile or Non-Volatile. During normal
operation, the electronic disk stores data in a large DRAM array, which is Volatile. But many
electronic disk devices contain a hidden magnetic hard disk and a battery for backup power.
If external power is interrupted, the electronic disk controller copies the data from RAM to the
magnetic disk. When external power is restored, the controller copies the data back into the
RAM.
The design of a complete memory system must balance all the factors. It must use only as
much expensive memory as necessary while providing as much inexpensive, Non-Volatile
memory as possible. Caches can be installed to improve performance where a large
access-time or transfer-rate disparity exists between two components.
I/O Structure
Storage is only one of many types of I/O devices within a computer. A large portion of
operating system code is dedicated to managing I/O, both because of its importance to
the reliability and performance of a system and because of the varying nature of the
devices. Next, we provide an overview of I/O. A general-purpose computer system
consists of CPUs and multiple device controllers that are connected through a common
bus. Each device controller is in charge of a specific type of device. Depending on the
controller, more than one device may be attached. For instance, seven or more devices
can be attached to the small computer-systems interface (SCSI) controller. A device
controller maintains some local buffer storage and a set of special-purpose registers.
The device controller is responsible for moving the data between the peripheral devices
that it controls and its local buffer storage. Typically, operating systems have a device
driver for each device controller. This device driver understands the device controller and
provides the rest of the operating system with a uniform interface to the device. To start
an I/O operation, the device driver loads the appropriate registers within the device
controller. The device controller, in turn, examines the contents of these registers to
determine what action to take (such as “read a character from the keyboard”). The
controller starts the transfer of data from the device to its local buffer. Once the transfer
of data is complete, the device controller informs the device driver via an interrupt that it
has finished its operation. The device driver then returns control to the operating system,
possibly returning the data or a pointer to the data if the operation was a read. For other
operations, the device driver returns status information. This form of interrupt-driven I/O
is fine for moving small amounts of data but can produce high overhead when used for
bulk data movement such as disk I/O. To solve this problem, direct memory access
(DMA) is used. After setting up buffers, pointers, and counters for the I/O device, the
device controller transfers an entire block of data directly to or from its own buffer
storage to memory, with no intervention by the CPU. Only one interrupt is generated per
block, to tell the device driver that the operation has completed, rather than the one
interrupt per byte generated for low-speed devices. While the device controller is
performing these operations, the CPU is available to accomplish other work. Some
high-end systems use switch rather than bus architecture. On these systems, multiple
components can talk to other components concurrently, rather than competing for cycles
on a shared bus. In this case, DMA is even more effective. Figure 1.5 shows the
interplay of all components of a computer system.
The input data travels from input unit to ALU. Similarly, the computed data travels from ALU
to output unit. The data constantly moves from storage unit to ALU and back again. This is
because stored data is computed on before being stored again. The control unit controls all
the other units as well as their data.
Input Unit
The input unit provides data to the computer system from the outside. So, basically it
links the external environment with the computer. It takes data from the input devices,
converts it into machine language and then loads it into the computer system.
Keyboard, mouse etc. are the most commonly used input devices.
Output Unit
The output unit provides the results of computer process to the users i.e it links the
computer with the external environment. Most of the output data is the form of audio
or video. The different output devices are monitors, printers, speakers, headphones
etc.
Storage Unit
Storage unit contains many computer components that are used to store data. It is
traditionally divided into primary storage and secondary storage. Primary storage is
also known as the main memory and is the memory directly accessible by the CPU.
Secondary or external storage is not directly accessible by the CPU. The data from
secondary storage needs to be brought into the primary storage before the CPU can
use it. Secondary storage contains a large amount of data permanently.
Arithmetic Logic Unit
All the calculations related to the computer system are performed by the arithmetic
logic unit. It can perform operations like addition, subtraction, multiplication, division
etc. The control unit transfers data from storage unit to arithmetic logic unit when
calculations need to be performed. The arithmetic logic unit and the control unit
together form the central processing unit.
Control Unit
This unit controls all the other units of the computer system and so is known as its
central nervous system. It transfers data throughout the computer as required
including from storage unit to central processing unit and vice versa. The control unit
also dictates how the memory, input output devices, arithmetic logic unit etc. should
behave.
Multi processor system - If there are multiple general-purpose CPU, then the system is a
multi-processor system.
Such systems have two or more processors in close communication, sharing the computer
bus and sometimes the clock, memory, and peripheral devices.
Key advantages :
I. Increased throughput.
By increasing the number of processors, we expect to get more work done in
less time.
The speed-up ratio with N processors is not N because a certain amount of
overhead is incurred in keeping all the parts working correctly.
This overhead, plus contention for shared resources, lowers the expected
gain from additional processors.
2. Economy of scale.
Multiprocessor systems can cost less than equivalent multiple
single-processor systems, because they can share peripherals, mass
storage, and power supplies.
If several programs operate on the same set of data, it is cheaper to store
those data on one disk and to have all the processors share them than to
have many computers with local disks and many copies of the data.
3. Increased reliability.
If functions can be distributed properly among several processors, then the failure of one
processor will not halt the system, only slow it down.
If we have ten processors and one fails, then each of the remaining nine processors can pick
up a share of the work of the failed processor. Thus, the entire system runs only 10 percent
slower, rather than failing altogether.
Graceful Degradation - The ability to continue providing service proportional to the level of
surviving hardware is called graceful degradation.
Fault tolerant - Systems that can suffer a failure of any single component and still continue
operation. Fault tolerance requires a mechanism to allow the failure to be detected,
diagnosed, and, if possible, corrected.
Types of Multiprocessing
Asymmetric multiprocessing, in which each processor is assigned a specific task. A boss
processor controls the system; the other processors either look to the boss for instruction or
have predefined tasks. This scheme defines a boss–worker relationship. The boss processor
schedules and allocates work to the worker processors.
Symmetric Multiprocessing(SMP) - in which each processor performs all tasks within the
operating system. SMP means that all processors are peers; no boss–worker relationship
exists between processors.
Features of multiprocessing :
Multiprocessing adds CPUs to increase computing power.
If the CPU has an integrated memory controller, then adding CPUs can also
increase the amount of memory addressable in the system.
Either way, multiprocessing can cause a system to change its memory access
model from uniform memory access (UMA) to non-uniform memory access
(NUMA).
UMA is defined as the situation in which access to any RAM from any CPU
takes the same amount of time. With NUMA, some parts of memory may take
longer to access than other parts, creating a performance penalty.
Dual Core Systems/ Multi core - Multiple computing cores on a single chip.
They can be more efficient than multiple chips with single cores because
on-chip communication is faster than between-chip communication.
In addition, one chip with multiple cores uses significantly less power than
multiple single-core chips.
It is important to note that while multicore systems are multiprocessor
systems, not all multiprocessor systems are multicore.
3. Clustered Systems - Combining multiple CPU’s together
Key Concepts:
Concurrency and Parallelism:
System Calls:
APIs: Application Programming Interfaces that allow programs to interact with the OS.
Trap Instructions: Software interrupts initiated by programs to request OS services.
Kernel:
Monolithic Kernel: The entire OS runs in a single address space.
Microkernel: Essential components run in kernel space, and other services run as
user-level processes.
Distributed lock manager - Functionality used to ensure that there is no resource conflict
when multiple hosts access the same resource.
Storage Area Networks
It allows many systems to attach to a pool of storage.
If the applications and their data are stored on the SAN, then the cluster software can assign
the application to run on any host that is attached to the SAN.
If the host fails, then any other host can take over. In a database cluster, dozens of hosts can
share the same database, greatly increasing performance and reliability.
The operating system keeps several jobs in memory simultaneously (Figure 1.9).
Since, in general, main memory is too small to accommodate all jobs, the jobs are
kept initially on the disk in the job pool.
This pool consists of all processes residing on disk awaiting allocation of main
memory.Job scheduler takes a set of jobs from this pool and brings it into memory
based on scheduling algorithms.
Multiprogrammed systems provide an environment in which the various system
resources (for example, CPU, memory, and peripheral devices) are utilized
effectively, but they do not provide for user interaction with the computer system.
When a process has to wait (for I/O for example), OS switches to another job.
Operating-System Operations
Modern operating systems are interrupt driven. If there are no processes to execute,
no I/O devices to service, and no users to whom to respond, an operating system will
sit quietly, waiting for something to happen. Events are almost always signaled by
the occurrence of an interrupt or a trap. A trap (or an exception) is a
software-generated interrupt caused either 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 service be performed. The interrupt-driven nature of an operating
system defines that system’s general structure. For each type of interrupt, separate
segments of code in the operating system determine what action should be taken.
An interrupt service routine is provided to deal with the interrupt. 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. With sharing, many processes could be adversely
affected by a bug in one program. For example, if a process gets stuck in an infinite
loop, this loop could prevent the correct operation of many other processes. More
subtle errors can occur in a multiprogramming system, where one erroneous
program might modify another program, the data of another program, or even the
operating system itself. Without protection against these sorts of errors, either the
computer must execute only one process at a time or all output must be suspect. A
properly designed operating system must ensure that an incorrect (or malicious)
program cannot cause other programs to execute incorrectly.
Dual-Mode Operation:
Dual-mode operation involves having two separate modes: user mode and kernel
mode.
The mode bit, usually a hardware feature, is used to distinguish between user mode
(1) and kernel mode (0).
The operating system executes in kernel mode, while user applications run in user
mode.
Transition between modes occurs during system calls, traps, or interrupts.
Privileged Instructions:
Privileged instructions are designated as potentially harmful and can only be
executed in kernel mode.
Examples of privileged instructions include those related to I/O control, timer
management, and interrupt management.
Hardware traps attempts to execute privileged instructions in user mode.
System Calls:
System calls allow user programs to request services from the operating system.
Invoking a system call involves a transition from user mode to kernel mode.
System calls are often implemented as traps to specific locations in the interrupt
vector.
The operating system's service routine handles the system call, verifies parameters,
and executes the requested service.
Modes Beyond Two:
Some systems, especially those supporting virtualization, may have more than two
modes.Virtual machine managers (VMMs) may operate in a mode with more
privileges than user processes but fewer than the kernel.
CPUs supporting virtualization may use additional modes beyond user and kernel
modes.
Error Handling:
Hardware protection, through dual-mode operation, helps detect errors that violate
modes.
Errors, such as illegal instructions or accessing unauthorized memory, result in traps
to the operating system.
The operating system handles errors by terminating the program, providing an error
message, and potentially creating a memory dump for analysis.
Timer:
A timer is used to prevent user programs from running indefinitely.
The timer can be set to interrupt the computer after a specified period.
It helps the operating system maintain control over the CPU and ensures user
programs do not monopolize resources.
The timer can be used to terminate a program if it exceeds a specified time limit.
Process management:
A program becomes a process when its instructions are executed by a CPU.
Processes can include time-shared user programs, system tasks, or any executable
code in execution. Processes can represent jobs, time-shared programs, and more.
Processes require various resources such as CPU time, memory, files, and I/O
devices to accomplish their tasks. Resources are allocated to processes either
during creation or while they are running. Initialization data, such as input, may be
passed to a process.
A program is a passive entity, like a file stored on disk, while a process is an active
entity in execution. A process has a program counter specifying the next instruction
to execute. A single-threaded process executes sequentially, while a multithreaded
process has multiple program counters for concurrent execution.
A process is considered the unit of work in a system. Systems consist of collections
of processes, including operating-system processes (executing system code) and
user processes (executing user code).
Storage Management:
The operating system provides users with a uniform, logical view of information
storage by abstracting the physical properties of storage devices. File management
involves mapping files onto physical media and accessing them through storage
devices. This encompasses creating and deleting files and directories, offering
primitives for file manipulation, and mapping files onto secondary storage.
Mass-storage management focuses on the efficient management of disks, including
tasks such as free-space management, storage allocation, and disk scheduling.
Caching:
A system must be able to distinguish among its users, typically maintained through a
list of user names and associated user identifiers (user IDs) or security IDs (SIDs) in
Windows. User authentication assigns a unique ID to each user, associated with
their processes and threads. Group functionality is introduced to distinguish sets of
users, with a system-wide list of group names and identifiers. Users can belong to
one or more groups, and group IDs are associated with processes and threads.
While user IDs and group IDs are sufficient for normal system use, users may need
to escalate privileges for certain activities, such as accessing restricted devices.
Operating systems provide methods for privilege escalation, such as the setuid
attribute on UNIX systems, which allows a program to run with the effective UID of
the file owner, gaining extra privileges for the duration of the program's execution.
Operating-System Services:
User interface
Almost all operating systems have a user interface (UI). This interface can take several
forms.Eg.1 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).Eg 2 batch interface, in which commands and directives to control those commands
are entered into files, and those files are executed.Eg 3 a graphical user interface (GUI) is
used.
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 display 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.
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 operating systems 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, 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.
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.
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 such as CPU cycles, main
memory, and file storage.
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.
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 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 himself or herself to the system, usually by means of a password,
to gain access to system resources.
System Calls
A system call is a routine that allows a user application to request actions that
require special privileges.
A system call is a method for a computer program to request a service from the
kernel of the operating system on which it is running. A system call is a method of
interacting with the operating system via programs. A system call is a request from
computer software to an operating system's kernel.
A series of sequence calls is required to perform file copy from one file to another
file.
Some operating systems include the command interpreter in the kernel, while others
treat it as a special program running when a job is initiated or when a user logs in.
Systems like Windows and UNIX offer multiple command interpreters known as
shells, such as the Bourne shell, C shell, Bourne-Again shell, Korn shell, etc.
The main function of a command interpreter is to get and execute the next
user-specified command, typically involving file manipulation (create, delete, list,
etc.).
Command interpreters can implement commands in two ways: either the interpreter
itself contains the code to execute the command, or most commands are
implemented through system programs.
The choice between command-line and GUI interfaces is often a matter of personal
preference.
System administrators and power users often prefer command-line interfaces for
efficiency and programmability, especially for repetitive tasks.
Windows users typically favor the GUI environment, while some systems provide
both GUI and command-line interfaces.
The design of a user interface is substantially removed from the actual system
structure, and the operating system focuses on providing adequate service to user
programs without distinguishing between user and system programs.
System Calls:
Services provided by an OS are typically related to any kind of operation that a user
program can perform like creation, termination, forking, moving, communication etc.
Similar types of operations are grouped into one single system call category. System
calls are classified into the following categories :
System Programs
Provide a convenient environment for program development and execution. Some of them
are simply user interfaces to system calls.
• File management
These programs create, delete, copy, rename, print, dump, list, and generally manipulate
files and directories.
• Status information
Some programs simply ask the system for the date, time, amount of available memory or
disk space, number of users, or similar status information. Others are more complex,
providing detailed performance, logging, and debugging information. Typically, these pro-
grams format and print the output to the terminal or other output devices or files or display it
in a window of the GUI. Some systems also support a registry, which is used to store and
retrieve configuration information.
File modification: Several text editors may be available to create and modify the content of
files stored on disk or other storage devices. There may also be special commands to
search contents of files or perform transformations of the text.
Programming-language support:
Compilers, assemblers, debuggers, and interpreters for common programming languages
(such as C, C++, Java, and PERL) are often provided with the operating system or available
as a separate download.
• Communications:
These programs provide the mechanism for creating
virtual connections among processes, users, and computer systems. They
allow users to send messages to one another's screens, to browse Web
pages, to send e-mail messages, to log in remotely, or to transfer files from
one machine to another.
Background services:
All general-purpose systems have methods for launching certain system-program
processes at boot time. Some of these processes terminate after completing their tasks,
while others continue to run until the system is halted. Constantly running system-program
processes are known as services, subsystems, or daemons.