Professional Documents
Culture Documents
OS Chapter 2
OS Chapter 2
following services are not for helping user but rather for ensuring
efficient operation of system itself
System Calls
System calls provide an interface to the operating system
services.
These calls are generally available as functions written in C/C++.
Example of How system calls are used:
We are writing a simple a program of transferring contents if one
file to other file.
1. Process Control
system calls:
end(): running program halts normally
abort(): running program halts ab-normally
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 is generated. The dump is
written to a special log file on disk and may be examined by a
debugger to detect bugs.
If the program discovers an error in its input and wants to
terminate abnormally, it may also want to define an error
level. More severe errors can be indicated by a higher-level
error parameter. It is then possible to combine normal and
abnormal termination by defining a normal termination as an
error at level 0.
load(): bringing a program in memory
execute(): executing a loaded program
create_process(): To create a new process,
terminate_process(): to terminate a process
In order to control a new process we need to be able to
get_process_attributes() and set_process_attributes()
wait_time(): waiting for existing process call to finish
wait_event(): waiting for a specific event to occur
signal_event(): Signalling the occurence of an event
when two or more processes share data. To ensure the
integrity of the data being shared, operating systems often
provide system calls allowing a process to lock shared data.
Then, no other process can access the data until the lock is
released. such system calls include acquire_lock() and
release_lock()
2. File Management
create() and delete() for creating and deleting files/directories
open() and close() for opening and closing files/directories
read(), write() and reposition() for reading, writing and re-
positioning file.
get_file_attributes() and set_file_attributes() for getting and
setting various file attributes.
move() and copy()
3. Device Management
A process may require several resource during its execution.
If the resources are available they can be granted and control can
be returned to the user process.
Otherwise, process will have to wait until sufficient resources are
available.
The various resources controlled by operating system can be
thought of as devices.
users on a multi-user system first need to request() device, then
after they are finished with the device they need to release() it.
We can read(), write() and reposition() devices.
4.Information Maintenance
Many system calls simply exist for the purpose of transferring the
information b/w user program and operating system.
for ex- system calls for getting current date, time, version number,
free-space, etc.
System calls to dump() memory are also provided for debugging
Operating system maintains information about all its processes
using system calls.
System calls are also used to get and set process information.
5.Communication
Inter-process communication can be of two types:
Message-Passing Model: Communicating processes
exchange messages with one another to transfer information.
Before communication a connection must be established, and the
name of the other communicator must be known. Each computer
in a network has a host name and each process has a process
name. The names can be translated into an identifier by
get_hostid() and get_processid() system calls.
open(), close(), open_connection() and close_connection() system
calls can then be provided.
accept_connection() for allowing communication to take place.
read_messages() and write_messages() system calls are used to
exchange messages b/w client and server
close_connection() call terminates the communication.
6.Protection
Protection provides a mechanism for controlling access to the
resources provided by a computer system.
set_permission() and get_permission(), manipulate the permission
settings of resources such as files and disks.
The allow_user() and deny_user() system calls specify whether
particular users can or cannot be allowed access to certain
resources.
System services
System services, also known as system utilities, provide a
convenient environment for program development and execution.
System programs are just bundle of useful system calls.
They can be divided into these categories:
Disadvantages :
Operating systems written in higher level languages have reduced
speed and require more storage.
Eg.
MS-DOS was written in Intel 8088 assembly language. As a result,
it is available only on Intel family of CPUs
Linux was written in C and is available on a number of different
CPUs, such as INTEL 80X86, Motorola 680X0, SPARC, etc.
Although operating systems are large, only a small amount of the
code is critical to high performance;
the interrupt handlers, I/O manager, memory manager, and CPU
scheduler are probably the most critical routines.
Operating-System Structure
An operating system must be engineered carefully for it to
function properly and modify easily.
Here we are going to discuss how operating system components
are interconnected and melded into a kernel.
1. Simple Structure
3. Layered Approach
In this approach the operating system is divided into a number of
layers (levels). The bottom layer (layer 0) is the hardware layer
and the highest layer (layer N) is the user interface layer.
Each higher level layer can invoke the functionalities of lower level
layer.
Each lower layer hides all the implementation and data structures
form higher layers and only provides functionality.
Advantages:
Simplicity of construction (each layer has limited and specific
functionality)
debugging - Layers are debugged from 0 to N, so when
debugging Mth layer and error occurs, then that error must
only be in Mth layer only, as all the lower layers have already
been debugged.
Disadvantages:
Challenges in defining appropriate functionality for each layer
Overall performance is poor due to the overhead of requiring
a user program to traverse through multiple layers to obtain
an operating-system service.
4. Microkernels
Micro-kernel approach structures the operating system by
removing all non-essential components from the kernel and
implementing them as user level programs that reside in separate
address spaces. The result is smaller kernel.
Mach OS was the first micro-kernel based OS.
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.
Advantages:
Extending the operating system is easier. All new services
are added to user space and consequently do not require
modification of the kernel.
OS is easier to port from one hardware design to another.
More security and reliability, since most services are running
as user—rather than kernel—processes. If a service fails, the
rest of the operating system remains untouched.
5.Modules
The best methodology by far for the operating system design is
loadable-kernel modules (LKMs).
Here Kernel is a set of core components and can link in additional
services via modules during run-time or at boot time.
This implementation is now used commonly in Linux, Unix, Solaris,
Windows, macOS
The idea of the design is for the kernel to provide core services,
while other services are implemented dynamically, as the kernel
is running.
6.Hybrid Systems
Operating systems generally combine different structures
resulting in hybrid systems.
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, 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.
macOS and iOS
Darwin
Darwin uses a hybrid structure.
System Boot
The process of starting a computer by loading the kernel is known
as booting the system.
steps included in booting are as follows:
1. A small piece of code known as the bootstrap program or boot
loader locates the kernel.
2. The kernel is loaded into memory and started.
3. The kernel initializes hardware.
4. The root file system is mounted.
Bootstrap programs also runs diagnostic to determine the state of
machine. —for example, inspecting memory and the CPU and
discovering devices.
If the diagnostics pass, the program can continue with the booting
steps. The bootstrap can also initialize all aspects of the system,
from CPU registers to device controllers and the contents of main
memory. Sooner or later, it starts the operating system and
mounts the root file system. It is only at this point is the system
said to be running.
Some computer systems use a multi-stage boot process:
When the computer is first powered on, a small boot loader
located in non-volatile firmware known as BIOS is run.
This initial boot loader usually does nothing more than load a
second boot loader, which is located at a fixed disk location called
the boot block.
The program stored in the boot block may be sophisticated enough
to load the entire operating system into memory and begin its
execution.
many computers have replaced BIOS-based boot process with
UEFI(Unified Extensible Firmware Interface),
because of the following advantages of UEFI:
1. It has better support for 64-bit systems and larger disks.
2. It is single, complete Boot manager and is then faster than
multistage BIOS boot process.
DTrace:
DTrace tool in Solaris, FreeBSD, Mac
OS X allows live instrumentation on
production systems
Probes fire when code is executed
within a provider, capturing state
data and sending it to consumers
of those probes
Example of following XEventsQueued
system call move from libc library to
kernel and back