Ktu B.Tech Cse S4 Note: Operating Systems
Ktu B.Tech Cse S4 Note: Operating Systems
Definition
An operating system is a program that acts as an interface between the
user and the computer hardware and controls the execution of all kinds of
programs.
KTU STUDENTS
Following are some of important functions of an operating System.
● Memory Management
● Processor Management
● Device Management
● File Management
● Security
● Job accounting
Module 11
Main memory provides a fast storage that can be accessed directly by the
CPU. For a program to be executed, it must in the main memory. An
Operating System does the following activities for memory management −
Processor Management
In multiprogramming environment, the OS decides which process gets the
processor when and for how much time. This function is called process
scheduling. An Operating System does the following activities for processor
management −
KTU STUDENTS
● De-allocates processor when a process is no longer required.
Device Management
An Operating System manages device communication via their respective
drivers. It does the following activities for device management −
● Keeps tracks of all devices. Program responsible for this task is known
as the I/O controller.
Decides which process gets the device when and for how much time.
● De-allocates devices.
File Management
A file system is normally organized into directories for easy navigation and
usage. These directories may contain files and other directions.
Module 12
KTU STUDENTS
computer system may be organized in different ways. Some computer
systems have single processor and other have multiprocessors. So
computer systems categorized in these ways.
Single Processor
Multiprocessor systems
Some systems have two or more processors. These systems are also known
as parallel systems or tightly coupled systems. Mostly the processors of
Module 13
KTU STUDENTS
relationship exits. In SMP systems many programs can run simultaneously.
But I/O must control to ensure that data reach the appropriate processor
because all the processor shares the same memory.
Clustered systems
Other form of clustered system includes parallel clusters and clustering over
a wide area network. In parallel cluster multiple hosts can access the same
data on the shared storage. So many operating systems provide this facility
but some special software is are also designed to run on a parallel cluster to
share data.
Module 14
The operating system must keep a lot of information about the current state
of the system. As things happen within the system these data structures
must be changed to reflect the current reality. For example, a new process
might be created when a user logs onto the system. The kernel must create
a data structure representing the new process and link it with the data
structures representing all of the other processes in the system.
Mostly these data structures exist in physical memory and are accessible
only by the kernel and its subsystems. Data structures contain data and
pointers, addresses of other data structures, or the addresses of routines.
Taken all together, the data structures used by the Linux kernel can look
very confusing. Every data structure has a purpose and although some are
used by several kernel subsystems, they are simpler than they appear at
first sight.
Linked Lists
KTU STUDENTS
data structures. On a lot of occasions it uses linked or chained data
structures. If each data structure describes a single instance or occurrence
of something, for example a process or a network device, the kernel must
be able to find all of the instances. In a linked list a root pointer contains the
address of the first data structure, or element, in the list, and then each
subsequent data structure contains a pointer to the next element in the list.
The last element's next pointer would be 0 or NULL to show that it is the
end of the list. In a doubly linked list each element contains both a pointer
to the next element in the list but also a pointer to the previous element in
the list. Using doubly linked lists makes it easier to add or remove elements
from the middle of list, although you do need more memory accesses. This
is a typical operating system trade off: memory accesses versus CPU cycles.
Hash Tables
Linked lists are handy ways of tying data structures together, but
navigating linked lists can be inefficient. If you were searching for a
particular element, you might easily have to look at the whole list before
you find the one that you need. Linux uses another technique, hashing, to
get around this restriction. A hash table is an array or vector of pointers. An
array, or vector, is simply a set of things coming one after another in
memory. A bookshelf could be said to be an array of books. Arrays are
accessed by an index, which is an offset into the array's associated area in
memory. Taking the bookshelf analogy a little further, you could describe
each book by its position on the shelf; you might ask for the 5th book.
Abstract Interfaces
KTU STUDENTS
Often these lower layers register themselves with the upper layer at boot
time. This registration usually involves adding a data structure to a linked
list. For example each filesystem built into the kernel registers itself with the
kernel at boot time or, if you are using modules, when the filesystem is first
used. You can see which filesystems have registered themselves by looking
at the file/proc/filesystems.
Computing Environments
Traditional
But blurred as most systems interconnect with others (i.e., the Internet)
Module 16
Client-Server Computing
File-server system provides interface for clients to store and retrieve files
Peer-to-Peer Computing
KTU STUDENTS
May each act as client, server or both
Broadcast request for service and respond to requests for service via
discovery protocol
Examples include Napster and Gnutella, Voice over IP (VoIP) such as Skype
Web-Based Computing
The Web has become ubiquitous, leading to more access by a wider variety
of device including PCs, workstations, handheld PDAs1 and even cell
phones as access point.
Module 17
Linux is the most famous open- source operating system, while Microsoft
Windows is a well-known example of the opposite closed source approach.
History
In the early days of modern computing (that is, the 1950s), a great deal of
software was available in open-source format.
KTU STUDENTS
Started by Free Software Foundation (FSF), which has “copy left” GNU
Public License (GPL)
Examples include GNU/Linux, BSD UNIX (including core of Mac OS X), and
Sun Solaris
Linux
The resulting GNU /Linux operating system has spawned hundreds of unique
or custom builds, of the system. Major distributions include RedHat, SUSE,
Fedora, Debian, Slackware, and Ubuntu.
BSD UNIX
Solaris
Module 18
Solaris can be compiled from the open source and linked with binaries of the
Utility
GNU ILinux, BSD UNIX, and Solaris are all open-source operating systems,
but each has its own goals, utility, licensing, and purpose.
The advantages of free software and open sourcing are likely to increase the
number and quality of open-source projects, leading to an increase in the
number of individuals and companies that use these projects.
KTU STUDENTS
Command Interpreter
o CLI or command interpreter allows direct command entry
➢ Sometimes implemented in kernel, sometimes by systems
program
➢ Sometimes multiple flavors implemented – shells
➢ Primarily fetches a command from user and executes it
➢ Sometimes commands built-in, sometimes just names of
programs
If the latter, adding new features doesn’t require shell
modification
GUI
➢ User-friendly desktop metaphor interface
➢ Usually mouse, keyboard, and monitor
➢ Icons represent files, programs, actions, etc
➢ Various mouse buttons over objects in the interface cause
various actions (provide information, options, execute function,
open directory (known as a folder)
➢ Invented at Xerox PARC
➢ Many systems now include both CLI and GUI interfaces
➢ Microsoft Windows is GUI with CLI “command” shell
➢ Apple Mac OS X is “Aqua” GUI interface with UNIX kernel
underneath and shells available
➢ Unix and Linux have CLI with optional GUI interfaces (CDE, KDE,
GNOME)
System Calls
Module 19
KTU STUDENTS
System Call Implementation
o Typically, a number associated with each system call
o System-call interface maintains a table indexed according to these
numbers
o The system call interface invokes the intended system call in OS
kernel and returns status of the system call and any return values
o The caller need know nothing about how the system call is
implemented
o Just needs to obey API and understand what OS will do as a result call
o Most details of OS interface hidden from programmer by API
o Managed by run-time support library (set of functions built into
libraries included with compiler)
Module 110
o Process control
➢ create process, terminate process
➢ end, abort
➢ load, execute
➢ get process attributes, set process attributes
➢ wait for time
➢ wait event, signal event
➢ allocate and free memory
➢ Dump memory if error
➢ Debugger for determining bugs, single step execution
➢ Locks for managing access to shared data between processes
o File management
➢ create file, delete file
➢ open, close file
➢ read, write, reposition
➢ get and set file attributes
Module 111
KTU STUDENTS
Standard C Library Example
➢ C program invoking printf() library call, which calls write()
system call
Example: MS-DOS
➢ Single-tasking
Module 112
Example: FreeBSD
o Unix variant
o Multitasking
o User login -> invoke user’s choice of shell
o Shell executes fork() system call to create process
➢ Executes exec() to load program into process
➢ Shell waits for process to terminate or continues with user
commands
o Process exits with:
➢ code = 0 – no error
Turning away from the user and system call interfaces, let us now take a
look at how to implement an operating system. In the next eight sections we
will examine some general conceptual issues relating to implementation
strategies. After that we will look at some low-level techniques that are often
helpful.
Layered Systems
A reasonable approach that has been well established over the years is
a layered system. Dijkstra's THE system (Fig. 1-25) was the first layered
operating system. UNIX (Fig. 10-3) and Windows 2000 (Fig. 11-7) also have
a layered structure, but the layering in both of them is more a way of trying
to describe the system than a real guiding principle that was used in building
the system.
For a new system, designers choosing to go this route should first very
carefully choose the layers and define the functionality of each one. The
bottom layer should always try to hide the worst idiosyncracies of the
hardware, as the HAL does in Fig. 11-7. Probably the next layer should
handle interrupts, context switching, and the MMU, so above this level, the
code is mostly machine independent. Above this, different designers will
have different tastes (and biases). One possibility is to have layer 3 manage
threads, including scheduling and inter thread synchronization, as shown
in Fig. 12-1. The idea here is that starting at layer 4 we have proper threads
that are scheduled normally and synchronize using a standard mechanism
(e.g., mutexes).
In layer 4 we might find the device drivers, each one running as a separate
thread, with its own state, program counter, registers, etc., possibly (but not
necessarily) within the kernel address space. Such a design can greatly
simplify the I/O structure because when an interrupt occurs, it can be
converted into an unlock on a mutex and a call to the scheduler to
KTU STUDENTS
(potentially) schedule the newly readied thread that was blocked on the
mutex. MINIX uses this approach, but in UNIX, Linux, and Windows 2000,
the interrupt handlers run in a kind of no-man's land, rather than as proper
threads that can be scheduled, suspended, etc. Since a huge amount of the
complexity of any operating system is in the I/O, any technique for making
it more tractable and encapsulated is worth considering.
Above layer 4, we would expect to find virtual memory; one or more file
systems, and the system call handlers. If the virtual memory is at a lower
level than the file systems, then the block cache can be paged out, allowing
the virtual memory manager to dynamically determine how the real memory
should be divided among user pages and kernel pages, including the cache.
Windows 2000 works this way.
Exokernels
While layering has its supporters among system designers, there is also
another camp that has precisely the opposite view (Engler et al., 1995).
Their view is based on the end-to-end argument (Saltzer et al., 1984). This
concept says that if something has to be done by the user program itself, it
is wasteful to do it in a lower layer as well.
Module 114
Client-Server Systems
KTU STUDENTS
A compromise between having the operating system does everything and
the operating system do nothing is to have the operating system do a little
bit. This design leads to a microkernel with much of the operating system
running as user-level server processes as illustrated in Fig. 1-27. This is the
most modular and flexible of all the designs. The ultimate in flexibility is to
have each device driver also run as a user process, fully protected against
the kernel and other drivers. Getting the drivers out of the kernel would
eliminate the largest source of instability in any operating system—buggy
third-party drivers—and would be a tremendous win in terms of reliability.
This approach keeps device drivers from examining (and damaging) kernel
data structures, which is (for the most part) a good thing. An analogous set
of calls could be made available to allow driver processes to read and write
kernel tables, but only in a controlled way and with the approval of the
kernel.
Module 115
Extensible Systems
With the client-server systems discussed above, the idea was to get as much
out of the kernel as possible. The opposite approach is to put more modules
into the kernel, but in a protected way. The key word here is protected, of
course. We studied some protection mechanisms in Sec. 9.5.6 that were
initially intended for importing applets over the Internet, but are equally
applicable to inserting foreign code into kernel. The most important ones are
sandboxing and code signing as interpretation is not really practical for
kernel code.
KTU STUDENTS
little more than a protection mechanism and then adding protected modules
to the kernel one at a time until reaching the functionality desired, a minimal
system can be built for the application at hand. In this view, a new operating
system can be tailored to each application by including only the parts it
requires. Paramecium is an example of such a system (Van Doorn, 2001).
Kernel Threads
KTU STUDENTS
read-only memory (EPROM), which is read only except when explicitly given
a command to become writable. All forms of ROM are also known as
firmware, since their characteristics fall somewhere between those of
hardware and those of software. A problem with firmware in general is that
executing code there is slower than executing code in RAM. Some systems
store the operating system in firmware and copy it to RAM for fast
execution. A final issue with firmware is that it is relatively expensive, so
usually only small amounts are available.
For large operating systems (including most general-purpose operating
Systems like Windows, Mac OS X, and UNIX) or for systems that change
frequently, the bootstrap loader is stored in firmware, and the operating
system is on disk. In this case, the bootstrap runs diagnostics and has a bit
of code that can read a single block at a fixed location (say block zero) from
disk into memory and execute the code from that block. The program stored
in the boot block may be sophisticated enough to load the entire operating
system into memory and begin its execution. More typically, it is simple code
(as it fits in a single disk block) and knows only the address on disk and
length of the remainder of the bootstrap program. is an example of an
open-source bootstrap program for Linux systems. All of the disk-bound
bootstrap, and the operating system itself, can be easily changed by writing
new versions to disk. A disk that has a boot partition (more on that in
Section 12.5.1) is called a boot disk or system disk.
Now that the full bootstrap program has been loaded, it can traverse
the file system to find the operating system kernel, load it into memory, and
start its execution. It is only at this point that the system is said to be
running.
Module 117