1.1 OS Struture, Operations and Types
1.1 OS Struture, Operations and Types
Introduction
• An operating system is a program that manages a computer’s hardware. It also provides
a basis for application programs and acts as an intermediary between the computer user
and the computer hardware.
• An amazing aspect of operating systems is how they vary in accomplishing these tasks.
Mainframe operating systems are designed primarily to optimize utilization of
hardware.
Personal computer (PC) operating systems support complex games, business
applications, and everything in between.
Operating systems for mobile computers provide an environment in which a user
can easily interface with the computer to execute programs.
• Thus, some operating systems are designed to be convenient, others to be efficient, and
others to be some combination of the two.
What Operating Systems Do
• A computer system can be divided roughly into four components: the hardware,
the operating system, the application programs, and the users (Figure 1.1).
• The hardware—the central processing unit (CPU), the memory, and the
input/output (I/O) devices—provides the basic computing resources for the system.
• 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.
• The operating system controls the hardware and coordinates its use among the
various application programs for the various users.
• We can also view a computer system as consisting of hardware, software, and data.
• There are two viewpoints in the operating systems: that of the user and that of the
system.
1.1.1 Operating System Structure
• General-purpose OS is very large program- A system as large and complex as a modern
operating system must be engineered carefully if it is to function properly and be
modified easily.
• A common approach is to partition the task into small components, or modules, rather
than have one single system.
• Various ways to structure ones
– Simple structure – MS-DOS
– More complex – UNIX
– Layered – an abstraction
– Microkernel – Mach
Simple Structure -- MS-DOS
• MS-DOS – written to
provide the most
functionality in the least
space
– Not divided into
modules
– Although MS-DOS has
some structure, its
interfaces and levels of
functionality are not
well separated
Simple Structure -- MS-DOS
• Advantages:
- Easy for kernel designer to develop simple OS.
• Disadvantages:
- Structure is very complicated as no clear boundaries exist
between modules.
- If any service fails, it leads to the failure of the entire system
- More security issues are always there.
1.1.1.1 Monolithic Structure
• The simplest structure for organizing an operating system is no structure at all. That
is, place all of the functionality of the kernel into a single, static binary file that
runs in a single address space. This approach—known as a monolithic structure—
is a common technique for designing operating systems.
• An example of such limited structuring is the original UNIX operating system,
which consists of two separable parts: the kernel and the system programs.
• The kernel is further separated into a series of interfaces and device drivers, which
have been added and expanded over the years as UNIX has evolved.
• We can view the traditional UNIX operating system as being layered to some
extent, as shown in Figure 2.12. Everything below the system-call interface and
above the physical hardware is the kernel.
• The kernel provides the file system, CPU scheduling, memory management, and
other operating system functions through system calls. Taken in sum, that is an
enormous amount of functionality to be combined into one single address space.
• The Linux operating system is based on UNIX and is structured similarly, as shown
in Figure 2.13. Applications typically use the glibc standard C library when
communicating with the system call interface to the kernel. The Linux kernel is
monolithic in that it runs entirely in kernel mode in a single address space,
Traditional UNIX System Structure-
Beyond simple but not fully layered
Linux System Structure - Monolithic plus modular design
1.1.1.2 Layered Approach
• The monolithic approach is often known as a tightly coupled system because changes to
one part of the system can have wide-ranging effects on other parts. Alternatively, we
could design a loosely coupled system. Such a system is divided into separate, smaller
components that have specific and limited functionality.
• All these components together comprise the kernel. The advantage of this layer approach
is that changes in one component affect only that component, and no others, allowing
system implementers more freedom in creating and changing the inner workings of the
system.
• The operating system is divided into a number of layers (levels), each built on top of
lower layers. The bottom layer (layer 0), is the hardware; the highest (layer N) is the
user interface.
• With modularity, layers are selected such that each uses functions (operations) and
services of only lower-level layers.
• The main advantage of the layered approach is simplicity of construction and debugging.
1.1.1.3 MicroKernels
• The original UNIX system had a monolithic structure. As UNIX expanded, the kernel
became large and difficult to manage. In the mid-1980s, researchers at Carnegie Mellon
University developed an operating system called Mach that modularized the kernel using
the microkernel approach.
• Figure 2.15 illustrates the architecture of a typical microkernel. The main function of the
microkernel is to provide communication between the client program and the various
services that are also running in user space. Communication is provided through message
passing.
• For example, if the client program wishes to access a file, it must interact with the file
server. The client program and service never interact directly. Rather, they communicate
indirectly by exchanging messages with the microkernel.
• Benefits of microkernel approach:
– Easier to extend a microkernel
– Easier to port the operating system to new architectures
– More reliable (less code is running in kernel mode)
– More secure
• The best-known illustration of a microkernel operating system is Darwin, the kernel
component of the macOS and iOS operating systems.
• Darwin, in fact, consists of two kernels, one of which is the Mach microkernel.
Another example is QNX, a real-time operating system for embedded systems. The
QNX Neutrino microkernel provides services for message passing and process
scheduling. It also handles low-level network communication and hardware interrupts.
All other services in QNX are provided by standard processes that run outside the
kernel in user mode.
• Unfortunately, the performance of microkernels can suffer due to increased system-
function overhead. When two user-level services must communicate, messages must
be copied between the services, which reside in separate address spaces.
• In addition, the operating system may have to switch from one process to the next to
exchange the messages. The overhead involved in copying messages and switching
between processes has been the largest impediment to the growth of microkernel-based
operating systems.
• Consider the history of Windows NT: The first release had a layered microkernel
organization. This version’s performance was low compared with that of Windows 95.
Windows NT 4.0 partially corrected the performance problem by moving layers from
user space to kernel space and integrating them more closely.
• By the time Windows XP was designed, Windows architecture had become more
monolithic than microkernel.
1.1.1.4 Modules
• Many modern operating systems implement loadable kernel modules (LKMs) in their
design
– Uses object-oriented approach
– Each core component is separate
– Each talks to the others over known interfaces
– Each is loadable as needed within the kernel
• Overall, similar to layers but with more flexible
– common in modern implementations of UNIX, such as Linux, macOS, and Solaris,
as well as Windows.
• Linux uses loadable kernel modules, primarily for supporting device drivers and file
systems. LKMs can be “inserted” into the kernel as the system is started (or booted)
or during run time, such as when a USB device is plugged into a running machine.
• If the Linux kernel does not have the necessary driver, it can be dynamically
loaded. LKMs can be removed from the kernel during run time as well. For Linux,
LKMs allow a dynamic and modular kernel, while maintaining the performance
benefits of a monolithic system.
Solaris Modular Approach
1.1.1.5 Hybrid Systems
• In practice, very few operating systems adopt a single, strictly defined structure. Instead,
they combine different structures, resulting in hybrid systems that address performance,
security, and usability issues.
• For example, Linux is monolithic, because having the operating system in a single
address space provides very efficient performance. However, it also modular, so that
new functionality can be dynamically added to the kernel.
• Windows is largely monolithic as well (again primarily for performance reasons), but it
retains some behavior typical of microkernel systems, including providing support for
separate subsystems (known as operating-system personalities) that run as user-mode
processes. Windows systems also provide support for dynamically loadable kernel
modules.
• The structure of three hybrid systems: the Apple macOS operating system and the two
most prominent mobile operating systems—iOS and Android.
1.1.1.5.1 macOS and iOS
• Apple’s macOS operating system is designed to run primarily on desktop and laptop
computer systems, whereas iOS is a mobile operating system designed for the iPhone
smartphone and iPad tablet computer.
• The general architecture of these two systems is shown in Figure 2.16. Highlights of the
various layers include the following:
• User experience layer. This layer defines the software interface that allows users to
interact with the computing devices. macOS uses the Aqua user interface, which is
designed for a mouse or trackpad, whereas iOS uses the Springboard user interface,
which is designed for touch devices.
• Application frameworks layer. This layer includes the Cocoa and Cocoa Touch
frameworks, which provide an API for the Objective-C and Swift programming
languages. The primary difference between Cocoa and Cocoa Touch is that the former is
used for developing macOS applications, and the latter by iOS to provide support for
hardware features unique to mobile devices, such as touch screens.
• Core frameworks. This layer defines frameworks that support graphics and media
including, Quicktime and OpenGL.
• Kernel environment. This environment, also known as Darwin, includes the Mach
microkernel and the BSD UNIX kernel.
• Some significant distinctions between macOS and iOS include the following:
1) Because macOS is intended for desktop and laptop computer systems, it is compiled to
run on Intel architectures. iOS is designed for mobile devices and thus is compiled for
ARM-based architectures. Similarly, the iOS kernel has been modified somewhat to
address specific features and needs of mobile systems, such as power management and
aggressive memory management. Additionally, iOS has more stringent security settings
than macOS.
2) The iOS operating system is generally much more restricted to developers than macOS
and may even be closed to developers. For example, iOS restricts access to POSIX and
BSD APIs on iOS, whereas they are openly available to developers on macOS.
• We now focus on Darwin, which uses a hybrid structure. Darwin is a layered system
that consists primarily of the Mach microkernel and the BSD UNIX kernel.
Darwin’s structure is shown in Figure 2.17.
• Whereas most operating systems provide a single system-call interface to the kernel—
such as through the standard C library on UNIX and Linux systems —Darwin provides
two system-call interfaces: Mach system calls (known as traps) and BSD system calls
(which provide POSIX functionality).
• The interface to these system calls is a rich set of libraries that includes not only the
standard C library but also libraries that provide networking, security, and progamming
language support (to name just a few).
• Beneath the system-call interface, Mach provides fundamental operating system
services, including memory management, CPU scheduling, and inter process
communication (IPC) facilities such as message passing and remote procedure calls
(RPCs). Much of the functionality provided by Mach is available through kernel
abstractions, which include tasks (a Mach process), threads, memory objects, and
ports (used for IPC).
• In addition to Mach and BSD, the kernel environment provides an I/O kit for
development of device drivers and dynamically loadable modules (which macOS refers
to as kernel extensions, or kexts).
• The overhead of message passing between different services running in user space
compromises the performance of microkernels. To address such performance problems,
Darwin combines Mach, BSD, the I/O kit, and any kernel extensions into a single
address space.
• Thus, Mach is not a pure microkernel in the sense that various subsystems run in user
space. Message passing within Mach still does occur, but no copying is necessary, as the
services have access to the same address space.
• Apple has released the Darwin operating system as open source. As a result, various
projects have added extra functionality to Darwin, such as the X- 11 windowing system
and support for additional file systems. Unlike Darwin, however, the Cocoa interface, as
well as other proprietary Apple frameworks available for developing macOS
applications, are closed.
1.1.1.5.2 Android OS
• Developed by Open Handset Alliance (mostly Google)
– Open Source
• Similar stack to iOS
• Based on Linux kernel but modified
– Provides process, memory, device-driver management
– Adds power management
• Runtime environment includes core set of libraries and Dalvik virtual machine
– Apps developed in Java plus Android API
• Java class files compiled to Java bytecode then translated to executable thnn
runs in Dalvik VM
• Libraries include frameworks for web browser (webkit), database (SQLite), multimedia,
smaller libc
1.1.2 Operating System Operations
• For a computer to start running—for instance, when it is powered up or rebooted—it
needs to have an initial program to run. The bootstrap program must know how to load
the operating system and how to start executing that system. To accomplish this goal, the
bootstrap program must locate the operating-system kernel and load it into memory.
• Once the kernel is loaded and executing, it can start providing services to the system and
its users. Some services are provided outside of the kernel by system programs that are
loaded into memory at boot time to become system daemons, which run the entire time
the kernel is running.
• 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.
• Another form of interrupt is a trap (or an exception), which 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 by executing a special operation called a system call.
1.1.2.1 Multiprogramming and
Multitasking
• An operating system provides the environment within which programs are executed.
• One of the most important aspects of operating systems is the ability to multiprogram. A
single program cannot, in general, keep either the CPU or the I/O devices busy at all
times. Single users frequently have multiple programs running.
• Multiprogramming increases CPU utilization by organizing jobs (code and data) so
that the CPU always has one to execute.
• The idea is as follows: 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.
• The set of jobs in memory can be a subset of the jobs kept in the job pool. The operating
system picks and begins to execute one of the jobs in memory.
• Eventually, the job may have to wait for some task, such as an I/O operation, to
complete. In a non-multiprogrammed system, the CPU would sit idle.
• In a multiprogrammed system, the operating system simply switches to, and executes,
another job. When that job needs to wait, the CPU switches to another job, and so on.
Eventually, the first job finishes waiting and gets the CPU back. As long as at least one
job needs to execute, the CPU is never idle.
• Example: Lawyer
• 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.
• Time sharing (or multitasking) is a logical extension of multiprogramming. In
time-sharing systems, the CPU executes multiple jobs by switching among them,
but the switches occur so frequently that the users can interact with each program
while it is running.
• Time sharing requires an interactive computer system, which provides direct
communication between the user and the system.
• The user gives instructions to the operating system or to a program directly, using
a input device such as a keyboard, mouse, touch pad, or touch screen, and waits for
immediate results on an output device. Accordingly, the response time should be
short—typically less than one second.
• A time-shared operating system uses CPU scheduling and multiprogramming to
provide each user with a small portion of a time-shared computer. Each user has at
least one separate program in memory. A program loaded into memory and
executing is called a process. When a process executes, it typically executes for
only a short time before it either finishes or needs to perform I/O.
• Time sharing and multiprogramming require that several jobs be kept
simultaneously in memory. If several jobs are ready to be brought into memory,
and if there is not enough room for all of them, then the system must choose among
them. Making this decision involves job scheduling.
• When the operating system selects a job from the job pool, it loads that job into memory
for execution. Having several programs in memory at the same time requires some form
of memory management.
• In addition, if several jobs are ready to run at the same time, the system must choose
which job will run first. Making this decision is CPU scheduling.
• Finally, running multiple jobs concurrently requires that their ability to affect one
another be limited in all phases of the operating system, including process scheduling,
disk storage, and memory management.
• In a time-sharing system, the operating system must ensure reasonable response time.
This goal is sometimes accomplished through swapping, whereby processes are
swapped in and out of main memory to the disk. A more common method for ensuring
reasonable response time is virtual memory, a technique that allows the execution of a
process that is not completely in memory.
• The main advantage of the virtual-memory scheme is that it enables users to run
programs that are larger than actual physical memory.
• Further, it abstracts main memory into a large, uniform array of storage, separating
logical memory as viewed by the user from physical memory. This arrangement frees
programmers from concern over memory-storage limitations.
1.1.2.2 Dual Mode and Multimode
Operation
• Since the operating system and its users share the hardware and software resources of the
computer system, a properly designed operating system must ensure that an incorrect (or
malicious) program cannot cause other programs —or the operating system itself—to
execute incorrectly.
• In order to ensure the proper execution of the system, we must be able to distinguish
between the execution of operating-system code and user-defined code. The approach
taken by most computer systems is to provide hardware support that allows
differentiation among various modes of execution.
• At the very least, we need two separate modes of operation: user mode and kernel
mode (also called supervisor mode, system mode, or privileged mode). A bit, called the
mode bit, is added to the hardware of the computer to indicate the current mode: kernel
(0) or user (1).
• Mode bit provided by hardware
– Provides ability to distinguish when system is running user code or kernel code.
– When a user is running mode bit is “user”
– When kernel code is executing mode bit is “kernel”
• How do we guarantee that user does not explicitly set the mode bit to “kernel”?
– System call changes mode to kernel, return from call resets it to user.
• The dual mode of operation provides us with the means for protecting the operating system
from errant users—and errant users from one another.
• We accomplish this protection by designating some of the machine instructions that may
cause harm as privileged instructions. The hardware allows privileged instructions to be
executed only in kernel mode.
• If an attempt is made to execute a privileged instruction in user mode, the hardware does
not execute the instruction but rather treats it as illegal and traps it to the operating system.
• The instruction to switch to kernel mode is an example of a privileged instruction. Some
other examples include I/O control, timer management, and interrupt management.
• The concept of modes can be extended beyond two modes. For example, Intel processors
have four separate protection rings, where ring 0 is kernel mode and ring 3 is user mode.
(Although rings 1 and 2 could be used for various operating-system services, in practice they
are rarely used.)ARMv8 systems have seven modes.
• The life cycle of instruction execution in a computer system.
• Initial control resides in the operating system, where instructions are executed in kernel
mode. When control is given to a user application, the mode is set to user mode. Eventually,
control is switched back to the operating system via an interrupt, a trap, or a system call.
Most contemporary operating systems—such as Microsoft Windows, Unix, and Linux—take
advantage of this dual-mode feature and provide greater protection for the operating system.
1.1.2.3 Timer
• We must ensure that the operating system maintains control over the CPU. We cannot
allow a user program to get stuck in an infinite loop or to fail to call system services and
never return control to the operating system.
• To accomplish this goal, we can use a timer. A timer can be set to interrupt the
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).
• A variable timer is generally implemented by a fixed-rate clock and a counter. The
operating system sets the counter. Every time the clock ticks, the counter is
decremented. When the counter reaches 0, an interrupt occurs. For instance, a 10-bit
counter with a 1-millisecond clock allows interrupts at intervals from 1 millisecond to
1,024 milliseconds, in steps of 1 millisecond.
• Before turning over control to the user, the operating system ensures that the timer is set
to interrupt. If the timer interrupts, control transfers automatically to the operating
system, which may treat the interrupt as a fatal error or may give the program more
time. Clearly, instructions that modify the content of the timer are privileged.
1.1.3 Types of Operating Systems
• An Operating System performs all the basic tasks like managing files, processes,
and memory. Thus operating system acts as the manager of all the resources, i.e.
resource manager. Thus, the operating system becomes an interface between user
and machine.
• Types of Operating Systems: Some widely used operating systems are as follows-
1. Batch Operating System
2. Time-Sharing Operating Systems
3. Distributed Operating System
4. Network Operating System
5. Real-Time Operating System
1.1.3.1 Batch Operating System
• This type of operating system does not interact with the computer directly. There is an
operator which takes similar jobs having the same requirement and group them into
batches. It is the responsibility of the operator to sort jobs with similar needs.
Advantages of Batch Operating System:
1. It is very difficult to guess or know the time required for any job to complete. Processors
of the batch systems know how long the job would be when it is in queue
2. Multiple users can share the batch systems
3. The idle time for the batch system is very less
4. It is easy to manage large work repeatedly in batch systems
Disadvantages of Batch Operating System:
1. The computer operators should be well known with batch systems
2. Batch systems are hard to debug
3. It is sometimes costly
4. The other jobs will have to wait for an unknown time if any job fails
Examples of Batch based Operating System: Payroll System, Bank Statements, etc.
1.1.3.1 Batch Operating System
1.1.3.2 Time-Sharing Operating
Systems
• Each task is given some time to execute so that all the tasks work smoothly. Each
user gets the time of CPU as they use a single system.
• These systems are also known as Multitasking Systems.
• The task can be from a single user or different users also.
• The time that each task gets to execute is called quantum.
• After this time interval is over OS switches over to the next task.
• The major benefit of working with these types of the operating system is that it is always
possible that one user can access the files or software which are not actually present on his
system but some other system connected within this network i.e., remote access is
enabled within the devices connected in that network.
Advantages of Distributed Operating System:
1. Failure of one will not affect the other network communication, as all systems are
independent from each other
2. Since resources are being shared, computation is highly fast and durable
3. Load on host computer reduces
4. These systems are easily scalable as many systems can be easily added to the network
5. Delay in data processing reduces
Disadvantages of Distributed Operating System:
1. Failure of the main network will stop the entire communication
2. To establish distributed systems the language which is used are not well defined yet
3. These types of systems are not readily available as they are very expensive. Not only
that the underlying software is highly complex and not understood well yet
Examples of Distributed Operating System are- LOCUS, etc.
1.1.3.3 Distributed Operating
Systems
1.1.3.4 Network Operating Systems
• These systems run on a server and provide the capability to manage data, users, groups,
security, applications, and other networking functions.
• These types of operating systems allow shared access of files, printers, security,
applications, and other networking functions over a small private network.
• One more important aspect of Network Operating Systems is that all the users are well
aware of the underlying configuration, of all other users within the network, their
individual connections, etc. and that’s why these computers are popularly known as
tightly coupled systems.
Advantages of Network Operating System:
1. Highly stable centralized servers
2. Security concerns are handled through servers
3. New technologies and hardware up-gradation are easily integrated into the system
4. Server access is possible remotely from different locations and types of systems
Disadvantages of Network Operating System:
1. Servers are costly
2. User has to depend on a central location for most operations
3. Maintenance and updates are required regularly
• Examples of Network Operating System are: Microsoft Windows Server 2003,
Microsoft Windows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD,
etc.
1.1.3.5 Real-time Operating Systems
• These types of OSs serve real-time systems. The time interval required to process and
respond to inputs is very small. This time interval is called response time.
• Real-time systems are used when there are time requirements that are very strict like
missile systems, air traffic control systems, robots, etc.
• Two types of Real-Time Operating System which are as follows:
• Hard Real-Time Systems:
• These OSs are meant for applications where time constraints are very strict and even
the shortest possible delay is not acceptable. These systems are built for saving life like
automatic parachutes or airbags which are required to be readily available in case of
any accident. Virtual memory is rarely found in these systems.
• Soft Real-Time Systems:
• These OSs are for applications where for time-constraint is less strict.
Advantages of RTOS:
1. Maximum Consumption
2. Task Shifting
3. Focus on Application
4. Real-time operating system in the embedded system
5. Error Free
6. Memory Allocation
Disadvantages of RTOS:
1. Limited Tasks
2. Use heavy system resources
3. Complex Algorithms
4. Device driver and interrupt signals
5. Thread Priority
• Examples of Real-Time Operating Systems are: Scientific experiments, medical
imaging systems, industrial control systems, weapon systems, robots, air traffic control
systems, etc.
1.1.3.5 Real-time Operating Systems