OS Unit 1
OS Unit 1
OS Unit 1
UNIT-1
Overview of Operating System
Introduction:
An operating system is a program that manages a computer’s hardware and
provide a basis for application programs and act as an intermediary between the
computer user and the computer hardware. Operating systems are vary based on
accomplishing the various tasks and system. Some operating system are designed
to optimize the utilization of hardware, some are design for supporting complex
games, business application and some are designed to provide simple interface
for the user. Therefore, some operating system are designed to be convenient,
other to be efficient and other to be some combination of the two.
Operating system exist because they offer a reasonable way to solve the problem
of creating a usable computing system. The fundamental goal of an operating
system is to execute user programs and to solve the user problem. To accomplish
this goal computer hardware and application software are developed. These
program require certain common operation such as those controlling the I/O
device. Thus the common function of controlling and allocating resources are
then brought together into one piece of software which is known as the operating
system.
An operating system is the one program running at all times on the computer
which is known as kernel. Along with the kernel, there are other two types of
program: system program which are associated with the operating but are not
usually part of kernel and application program which includes all the program not
associated with the operation of the system.
Operating System Goals:
• Execute the user program and to solve the user problem easily.
• Make the computer system convenient to use.
• Use the computer hardware in efficient manner.
• Proper utilization of the resources.
Advantages:
• Low setup cost over more job.
• Keeps machine busy while programmer thinks of problem and
managing job.
Disadvantages:
• Lack of interaction between user and the job.
• Difficult to provide desired priority.
• If bugs are received, memory and register are dumped then job have
to be submitted again.
• CPU is often idle because the speed of IO device is less than CPU
processing speed.
• User have to wait for result until batches are collected and submitted.
Advantages:
• Provide quick response.
• Reduce CPU Idle time
Disadvantages:
• More complex job scheduling and memory management.
• Problem of reliability.
• Problem of data communication
Advantages:
• Due to resource sharing facility user at one site may be able to use
the resource available at another site.
• If one site fail, the remaining site can potentially continue operating.
• Reduction in delay in data processing.
Disadvantages:
• Harder to manage network.
• Provide less autonomous environment.
Advantages:
• Fast response and processing time
Disadvantages:
• Fixed time constraints.
2. Memory Management:
The main memory is the central to the operation of a modern computer
system. Main memory is a large array of bytes and each byte has its own
address. The central processor reads the instruction from the main memory
during instruction fetch cycle and both read and write data from main
memory during data fetch cycle. To improve the CPU utilization and the
speed of the computer’s response time all the program should be kept in
memory which required proper memory management.
Thus, operating system is responsible for the following activities for
memory management:
• Keeping track of which part of memory are currently being used and
who is using them.
• Deciding which processes or part of the processes and data to move
into and out of memory.
• Allocating and deallocating memory space as needed.
3. Process Management:
A program does nothing unless its instruction are executed by a CPU. A
program loaded in the memory and executing (i.e. a program in execution)
is known as process. For e.g. a word processing program being run by an
individual user on a PC is a process. A program is the passive entity, like
the contents of a file stored on disk whereas a process is an active entity.
A process can be single threaded and multi-threaded and depending on this
their execution and resource requirement are different. There might be
several process executing concurrently and the resources are either given
when it is created or allocated when it is running. So, for the proper
execution of the process their proper management is required. Thus, the
4. Storage Management:
To make the computer system convenient for users, the operating system
provides a uniform, logical view of information storage. A file is a
collection of related information defined by its creator. The operating
system maps the file onto the physical media and access these files via the
storage device. Computer can store information on several different types
of physical media like magnetic tape and each device has its own physical
organization. The operating system implements abstract concept of file by
managing mass-storage media such as tapes and disks. Files are normally
organized into directories to make them easier to use and when particular
file is accessed by multiple user it may be desirable to control which user
may access a file. The operating system handles both file system and mass
storage system.
Following are the function of operating system in connection to file system
and mass storage management:
• Creating and deleting file
• Creating and deleting directories
• Mapping file into secondary storage.
• Backing up file on stable storage media
• Free space management (mass storage management)
• Disk scheduling (mass storage management)
• Storage allocation (mass storage management)
to device controller to memory content. To load the operating system and to start
executing the system, the bootstrap program must locate the operating system
kernel and load it into memory. Once the kernel is loaded and executing. It can
starts providing service to the system and its user.
The occurrence of any event is signaled by an interrupt from either the hardware
or the software. When the CPU is interrupted, it stops what it is doing and transfer
the execution to a fixed location which contains the starting address where the
service routine for an interrupt is located. Then the interrupt service starts and on
completion CPU resumes the interrupted computation.
In the time-sharing system, the CPU executes multiple job by switching among
them. Here, the user gives instruction to the operating system using input devices
and wait for immediate result on an output devices. So the response time should
be short typically less than one second. The operating system uses the CPU
scheduling and multiprogramming to provide each user with a small portion of
time shared computer. Operating system also uses memory management, job
scheduling, CPU scheduling for managing all the jobs and loading them into
memory.
System Structure:
Operating System Service:
An operating system provides an environment for the execution of programs. I
provides certain service for the programs and for the user of the program. The
service provided are differ from one operating system to another. Following
figure shows the one view of various operating system service and how they are
interrelate. Here, service provided are divided into two set, one which is helpful
for the user and another one is for ensuring efficient operation of the system itself.
Following are the operating system service that are helpful to the user:
1. User Interface:
Almost all operating system have a user interface which can take several
forms. One is command line interface (CLI) which uses the text command
and a method for entering them. Another is batch interface, in which
commands and directives to control those command are entered into files
and executed. Another is a graphical user interface (GUI) which is
commonly used now days and is a window system with pointing device to
direct I/O, choose from menus, makes selection and keyword to enter text.
2. 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 the execution either normally
or abnormally. These all are controlled by operating system.
3. I/O Operation:
A running program may require I/O operation which may involve file or
an I/O device and for specific device, special function may require. For
efficiency and protection user cannot control I/O devices directly so,
operating system must provide means to do I/O.
4. File-System Manipulation:
Program needs to read and file and directories. They also need to create
and delete them, search them, list the information etc. some operating
system includes permission management to allow or deny access to files or
directories based on ownership where some provides a variety of file
system to allow personal choices and to provide specific features.
5. Communication:
There are many situation in which one process needs to exchange the
information to another process and such communication may occur
between the processes that are executing in same computer or executing on
different computer tied together by some form of network.
Communication may be implemented via shared memory in which two or
more processes read and write to shared section of memory or message
passing in which packet of information in predefined formats are moved
between processes by an operating system.
6. Error Detection:
The operating system needs to be detecting and correcting errors
constantly. Error may occur in the CPU and memory hardware (such as
power failure), in I/O device (such as connection failure to network, lack
of paper in printer) and in the user program (such as attempt to access an
illegal memory, over uses of CPU time). For each type of error, operating
system should take the appropriate action to ensure correct and consistent
computing. Sometimes it might terminate an error causing process or it
might halt the system if it has no choice.
Following are the set of operating system function exists for ensuring the efficient
operation of the system:
1. Resource allocation:
When there are multiple users or multiple jobs running at the same time,
resource must be allocated to each of them. The operating system manages
different types of resources. Some (such as CPU cycle, main memory) may
have special allocation code whereas other (such as I/O devices) may have
general request and release code. For the uses of best CPU time, operating
system have CPU scheduling which takes different aspect like speed of
CPU, number of register available etc.
2. Accounting:
Operating system keep track of which user uses how much and what kinds
of computer resources. This recording may be used for accounting for
accumulating usage statistics. These records may be valuable tool for
researcher who wish to reconfigure the system to improve computing
service.
2. Layered approach:
Operating system can be broken down into smaller form with proper
hardware support due to which much more control over the computer can
be retained. A system can be made modular in many ways and one method
is the layered approach in which operating system is broken into a number
of layers (levels). The bottom layer is the hardware and the highest layer
(layer n) is the user interface. The layer consists of the data structure and
set of routines that can invoked by the higher level layers (i.e. higher layer
invoke operation on lower layer). The layers only knows what a particular
operations do, it does not need to know how the operation are implemented.
Following figure shows the structure of layered approach.
3. Microkernels:
This method structures the operating system by removing all non-essential
components from the kernel and implementing them as a system and user
level program. This results in smaller kernel and provide minimum process
and memory management. The main function of microkernel is to provide
communication between the client program and the various service that are
also running in the user space. Communication is provided through
message passing (message is exchanged between the process either directly
or indirectly through a common mailbox. The client program and service
never interact directly. They have to communicate indirectly by changing
message with the microkernel.
The advantage of this structure is that it makes extending of OS easier. All
services are added to user space and do not require modification of the
kernel which makes changes to be fewer. It also provide more security and
reliability since, most of the service are running as a user and if a service
fail the rest of the OS remain untouched.
The following figure shows the structure of microkernel approach.
System Calls:
System calls provide an interface to the services made available by an operating
system. These calls are generally available as routines written in C and C++.
System executes thousands of system call per second. Following example
illustrate how system call are used.
Let us consider we need to write a simple program to read data from one file and
copy them to another file. For this the program will need the name of the files at
first which can be specified in many ways. In mouse based system it can be done
by choosing the file name displayed in window. This sequence requires many I/O
system call.
Once the file name have been obtained, the program must run the input file and
create output file. This operation also required another system call. If the error
occur on processing the input file program should respond with error message,
which requires another system call. When the both files are set up we enter in a
loop that reads from the input file and writes to the output file (another system
call).
Each read and write operation must return status information regarding various
possible error conditions. This required another form of system call. Finally, after
all the entire file is copied program may closed both files and return the status
information, which requires another system call. This sequence are shown in
figure below.
Threads:
Threads like process are a mechanism to allow a program to do more than one
thing at a time. Conceptually, threads exist within the process and finer-grained
unit of execution. Thread is the basic unit of CPU utilization; it comprises a thread
id, a program counter, register set and stack. Traditionally, the thread has its own
address space and a single thread of control. This single thread of control allows
the process to perform only one task at a time. For example: user cannot
simultaneously type in character and run the spell checker at a time.
If a process has multiple thread of control, it can perform more than one task at a
time. All thread shares the same address space, global variable, set of open file,
child process, alarms and signal etc. for example: a web browser may have a one
thread displaying a image while another thread retrieving the data from the
network.
Following figure illustrate the difference between a traditional single-threaded
process and a multithreaded process.
In multithreaded, the process will create a multiple thread for different service
request due to which multiple request can be execute in single time. Most
operating system kernel are now multithreaded. Several threads operate in the
kernel and each thread performs a specific task such as managing device,
managing memory or interrupt handling.
Following figure shows multithreaded server architecture:
Multithreading Models:
Support for thread may be provided either at the user level for user thread or by
the kernel for kernel threads. User threads are supported above the kernel and are
managed without kernel support whereas kernel threads are supported and
managed directly by the operating system. A relationship must exist between user
thread and kernel threads. Following three model provides a common way to
establish such relationship:
1. Many to One Model:
This model maps many user level threads to one kernel thread. Thread
management is done by thread libraries in user space so it is efficient.
Entire process will be block if a thread makes a blocking system call. As
only one thread can access kernel at a time multiple thread are unable to
run in parallel. A thread library available for Solaris system (green thread)
and early version of java used this model.
Thread Libraries:
It provides the programmer with an API for creating and managing thread. There
are two primary ways of implementing a thread library. The first approach is to
provide a library entirely in the user space with no kernel support in which all
code and data structure exist in the user space. Here invoking a function in the
library results in a local function call in user space and not a system call.
The second approach is to implement a kernel level library supported directly by
the OS. Code and data structure for the library exist in kernel space and invoking
a function in the API for the library typically results in a system call to the kernel.
Three main thread libraries are in use today: POSIX Pthread, windows and java.
Pthreads:
It refers to the POSIX standard defining an API for thread creation and
synchronization. This is a specification for thread behavior not an
implementation.
Following program shows the basic Pthread API for constructing a multithreaded
program.
#include <pthread.h>
#include <stdio.h>
int sum;
void *runner (void *param);
int main (int argc, char *argv[ ]){
pthread_t tid;
pthread_attr_t attr;
if (argc!=2){
fprintf(stderr, “usage: a.out <integer value>/n”);
return -1;
}
if(atoi(argv[1] <0){
fprintf(stderr, “%d must be >=0 \n”, atoi(argv[1]));
return -1;
}
Pthread_attr_init(&attr);
Pthread_create(&tid, &attr, runner, argv[1]);
Pthread.join(tid, NULL);
Printf(“sum = %d\n”, sum);
}
void *runner (void *param){
int I, upper = atoi(param);
sum = 0;
for(i=1; i<=upper; i++){
sum +=1;
pthread.exit(0);
}
}