Operating Systems
An operating system is system software that manages a computer’s hardware or we can say that it acts as a communication bridge (interface) between the user and computer hardware. The purpose of an operating system is to provide a platform on which a user can execute programs in a convenient and efficient manner.
The main task of an operating system is to carries out the allocation of resources and services, such as allocation of memory, devices, processors and information. The operating system also includes programs to manage these resources, such as a traffic controller, a scheduler, memory management module, I/O programs, and a file system.
Operating system goals:
- Execute
user programs and make solving user problems easier.
- Make
the computer system convenient to use.
- Use
the computer hardware in an efficient manner.
Computer System Components
1.
Hardware – provides basic
computing resources (CPU, memory, I/O devices).
2.
Operating system – controls and
coordinates the use of the hardware among the various application programs for
the various users.
3.
Applications
programs
– Define the ways in which the system resources are used to solve the computing
problems of the users (compilers, database systems, video games, business
programs).
4.
Users (people,
machines, other computers).
Computer-System Organization
A modern general-purpose
computer system consists of one or more CPUs and a number of device controllers
connected through a common bus that provides access between components and shared
memory. 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. 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. In the following subsections, we
describe some basics of how such a system operates, focusing on three key
aspects of the system. We start with interrupts, which alert the CPU to events
that require attention. We then discuss storage structure and I/O structure.
Computer-System Architecture
Single-Processor Systems
Multiprocessor Systems
Classification/Types of Operating Systems
There are 6 major types of Operating System which are given below,
1. Batch Operating System
Users of batch OS cannot interact with the computer directly. So,
Each user puts his job on an offline device like punches cards and submits it
to the computer operator. Then by computer Operator, same type of processes are
grouped together and treated as a batch. Such types of operating system was use
earlier. Lets explain with diagram given below,
Advantages Of Batch OS
·
If
a job takes a very long time(1 day or so) Then, such processes can be executed
even in the absence of any humans. thus, such operating systems are very useful
in some cases i.e. same type of bank statement.
Limitations Of Batch OS
- Suppose I/O or an error occurs in one process of a batch. Then, all the remaining process gets affected. They have to wait until the I/O completed or error is resolved.
- It follow FCFS algorithm. There may be a possibility of short process have to wait for long time due to execution of heavy process first
Examples of Batch Operating System are Payroll System, Bank
Statements etc.
2.
Time Sharing OS
In general, when a process starts executing on CPU, it will occupy
the CPU till its completion. But, Sharing of CPU among the different users or
processes for quantum period of time is called time sharing OS. CPU
scheduling Algorithms are used for CPU Sharing .This short period of time
during that a user gets attention of the CPU is known as time slice or time
Quantum. Each process from user is given some time to execute, so that all the
processes work properly. Due to so fast Context switching, it looks all
processes are running at the same time on CPU. But in real, each task gets time
of CPU as they use single system. Time Sharing is a multitasking
but explained in two different terms. But the concept is the same in
both terms. Have a look
Single
user time Sharing OS
Time sharing is a method where the resources like CPU, Main memory
are shared among the different tasks at the same time by means of
multi-programming and multi-tasking is called time sharing Operating System.
Multi user time Sharing OS
Time sharing is a method where the resources like CPU, Main memory
are shared among the different users at the same time by means of
multi-programming and multi-tasking is called time sharing Operating system.
For efficient performance and implementation an OS should be partitioned into separate subsystems, each with carefully defined tasks, inputs, outputs, and performance characteristics. These subsystems can then be arranged in various architectural configurations:
1. Simple Structure
When DOS was originally written its developers had no idea how big and important it would eventually become. It was written by a few programmers in a relatively short amount of time, without the benefit of modern software engineering techniques, and then gradually grew over time to exceed its original expectations. It does not break the system into subsystems, and has no distinction between user and kernel modes, allowing all programs direct access to the underlying hardware. (Note that user versus kernel mode was not supported by the 8088-chip set anyway, so that really wasn't an option back then.)
MS-DOS layer structure
2. Layered Approach
Another approach is to break the OS into a number of smaller layers, each of which rests on the layer below it, and relies solely on the services provided by the next lower layer.
This approach allows each layer to be developed and debugged independently, with the assumption that all lower layers have already been debugged and are trusted to deliver proper services.
The problem is deciding what order in which to place the layers, as no layer can call upon the services of any higher layer, and so many chicken-and-egg situations may arise.
Layered approaches can also be less efficient, as a request for service from a higher layer has to filter through all lower layers before it reaches the HW, possibly with significant processing at each step.
System Call?
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.
The Application Program Interface (API) connects the operating system's functions to user programs. It acts as a link between the operating system and a process, allowing user-level programs to request operating system services. The kernel system can only be accessed using system calls. System calls are required for any programs that use resources.
How are system calls made?
When a computer software needs to access the operating system's kernel, it makes a system call. The system call uses an API to expose the operating system's services to user programs. It is the only method to access the kernel system. All programs or processes that require resources for execution must use system calls, as they serve as an interface between the operating system and user programs.
Types of System Calls
There are commonly five types of system calls. These are as follows:
- Process Control
- File Management
- Device Management
- Information Maintenance
- Communication
Process Control
Process control is the system call that is used to direct the processes. Some process control examples include creating, load, abort, end, execute, process, terminate the process, etc.
File Management
File management is a system call that is used to handle the files. Some file management examples include creating files, delete files, open, close, read, write, etc.
Device Management
Device management is a system call that is used to deal with devices. Some examples of device management include read, device, write, get device attributes, release device, etc.
Information Maintenance
Information maintenance is a system call that is used to maintain information. There are some examples of information maintenance, including getting system data, set time or date, get time or date, set system data, etc.
Communication
Communication is a system call that is used for communication. There are some examples of communication, including create, delete communication connections, send, receive messages, etc.
Examples of Windows and Unix system calls
There are various examples of Windows and Unix system calls. These are as listed below in the table:
Process | Windows | Unix |
---|---|---|
Process Control | CreateProcess() ExitProcess() WaitForSingleObject() | Fork() Exit() Wait() |
File Manipulation | CreateFile() ReadFile() WriteFile() CloseHandle() | Open() Read() Write() Close() |
Device Management | SetConsoleMode() ReadConsole() WriteConsole() | Ioctl() Read() Write() |
Information Maintenance | GetCurrentProcessID() SetTimer() Sleep() | Getpid() Alarm() Sleep() |
Communication | CreatePipe() CreateFileMapping() MapViewOfFile() | Pipe() Shmget() Mmap() |
What is Kernel?
- Kernel is a computer program that is a core or
heart of an operating system. Hence it has full control over everything in
the system. Kernel handles all operations on behalf of operating system. Kernel
first loaded on start-up the system (After the bootloader). Once it is
loaded, it manages the remaining start-ups. A kernel is kept and usually
loaded into separate memory space, known as protected Kernel space (kernel
mode). Other application programs such as browser, word processor,
audio & video player use separate memory space known as user-space (user mode).
- Due to these two separate spaces; user data and
kernel data don't interfere with each other and do not cause any
instability and slowness.
Explanation of System Call
As in below diagram, User Applications run in user mode, and operating system run in kernel mode. As OS control all the hardware’s so User cannot access hardware without kernel mode. To access kernel mode user application generate a system call because System call is a source to go to kernel mode.
CPU switch in two modes, while working
- User mode
- Kernel mode
User-mode and kernel mode
User Mode
When an application like MS word handling a text editor runs on the operating system, the system is in user mode and the mode bit is 1 in that case. The mode bit will change from 1 to 0 if it switches to kernel mode. The user mode to kernel mode is switched when there is a need to access any device or any interrupt/system call occurs.
Kernel-mode
When the system boots, the system
starts with kernel mode. And the applications are executed in user mode. The
switch can happen from user mode to kernel mode when
· Interrupt
occurs
· Need to access privileged instruction
· Need to access any device
· The mode bit is changed from 0 to 1 in case of the
system switch back to user mode.
Types of Kernel
There are mainly five types of
Kernel, which are given below:
1.
Monolithic Kernel
2.
Microkernel
3.
Hybrid Kernel
4.
Nano Kernel
5.
Exo Kernel
· Monolithic Kernel: Monolithic
kernels are the
simplest and most common type of Kernel. They include the core functionality of
the operating system and support all devices connected to it. In this, the user
and kernel services are implemented in the same memory space. Due to this, the
size of the kernel increases, which in turn increases the size of the operating
system. The main benefit is that the process execution is faster as there is no
separate memory space for the user and Kernel.
Advantage:
It has good performance.
Disadvantage: It has dependencies between
system components.
· Microkernel: In
this, user services and kernel services are implemented into two different
address spaces: user space and kernel space. Since it uses different spaces for
both the services, so, the size of the microkernel is decreased, and which also
reduces the size of the OS. Only some essential services are provided by
microkernels, such as defining memory address spaces, IPC (Interprocess
Communication), and process management. Other services such as networking are
not provided by Kernel and handled by a user-space program known
as servers. One of the main disadvantages of monolithic kernels that an
error in the kernel can crash the whole system, can be removed in the
microkernel. As in a microkernel, if a kernel process crashes, the crashing of
the whole system can still be prevented by restarting the error-caused
services.
Advantage: It is more stable.
Disadvantage: There are lots of system
calls and context switches.
· Hybrid Kernel: Hybrid
kernels combine monolithic and microkernels. They include more services than
microkernels but less than monolithic kernels. This allows them to offer some
of the benefits of both kernels. It borrows speed from the monolithic kernels
and modularity from microkernels.
Advantage: It
combines both monolithic kernel and microkernel.
Disadvantage: It
is still similar to monolithic kernel.
· Nano Kernel: Nano
kernels are the smallest type of Kernel, consisting of only a few thousand
lines of code. It means that the code executing in the privileged mode of the
hardware is minimal. They are used primarily in embedded systems or devices
with limited resources.
Advantage: It offers hardware
abstractions without system services.
Disadvantage: It
is quite same as Microkernel hence it is less used.
· Exo Kernel: This
Kernel has separate resource protection and management. It is suitable for use
when performing application-specific customization. Exo kernels are designed
for use in mobile
devices.
They are a variation of microkernels that include additional features
specifically for mobile devices, such as power management and support for
multiple processors.
Advantage: It has fewest hardware
abstractions.
Disadvantage: There is more work for
application developers.
What is Shell
A shell is special user
program which provide an interface to user to use operating system services. Shell
accept human readable commands from user and convert them into something which
kernel can understand. It is a command language interpreter that execute
commands read from input devices such as keyboards or from files. The shell gets
started when the user login or start the terminal. Shell may have either
a command line interface (C.L.I.) or a graphical user interface
(G.U.I.).
Types of Shells in Operating
Systems
A shell script is a computer program designed
to be run by the Unix/Linux shell which could be one of the following:
Ø The
Bourne Shell
Ø The C
Shell
Ø The Korn
Shell
Ø The GNU
Bourne-Again Shell
Ø
Bourne shell − If you are using a
Bourne-type shell, the $ character is the default prompt.
The
Bourne Shell has the following subcategories −
· Bourne
shell (sh)
· Korn
shell (ksh)
· Bourne
Again shell (bash)
· POSIX
shell (sh)
Ø
C shell − If you are using a C-type
shell, the % character is the default prompt.
The
different C-type shells follow −
· C shell
(csh)
· TENEX/TOPS
C shell (tcsh)
Difference between Shell and Kernel:
Let’s explain User Mode vs Kernel Mode with examples
When system is Turn ON then CPU is in kernel mode, by default, because it loading OS into main memory and OS exist in Kernel mode. After log IN, CPU switch to user mode to run user applications.
1. Watching Movie in windows OS,
If we want To play movie then we have to double click on that particular video. As, that video exist in main memory and main memory is hardware. So, CPU cannot access the hardware in user mode. System have to request through system call to open the file in main memory. So, OPEN () system call is generated and CPU switch to Kernel mode. Now OS in kernel, open that particular file from main memory. After opening the file CPU switch back to user mode. Now we are watching the movie in user mode. When user want to close the file then CLOSE system call again generated.
2. Using MS WORD
To open MS WORD we have to double click on that particular file. As, that file exist in main memory and main memory is a hardware. So, User cannot access the hardware in user mode. User have to request through system call to open the file in main memory. So, OPEN () system call is generated and CPU switch to Kernel mode. Now OS is in kernel mode, it open that particular file from main memory. After opening the file, CPU switch back to user mode. Now we are writing some text in user mode. When user want to save the file then WRITE () system call is again generated. CPU switches to kernel mode to save the file in main memory.
Functions of an Operating System
Memory Management
The operating system manages the Primary Memory or Main Memory. Main memory is made up of a large array of bytes or words where each byte or word is assigned a certain address. Main memory is fast storage and it can be accessed directly by the CPU. For a program to be executed, it should be first loaded in the main memory. An Operating System performs the following activities for Memory Management:
- It keeps track of primary memory, i.e., which bytes of memory are used by which user program. The memory addresses that have already been allocated and the memory addresses of the memory that has not yet been used.
- In multiprogramming, the OS decides the order in which processes are granted memory access, and for how long.
- It Allocates the memory to a process when the process requests it and deallocates the memory when the process has terminated or is performing an I/O operation.
The operating system manages the Primary Memory or Main Memory. Main memory is made up of a large array of bytes or words where each byte or word is assigned a certain address. Main memory is fast storage and it can be accessed directly by the CPU. For a program to be executed, it should be first loaded in the main memory. An Operating System performs the following activities for Memory Management:
- It keeps track of primary memory, i.e., which bytes of memory are used by which user program. The memory addresses that have already been allocated and the memory addresses of the memory that has not yet been used.
- In multiprogramming, the OS decides the order in which processes are granted memory access, and for how long.
- It Allocates the memory to a process when the process requests it and deallocates the memory when the process has terminated or is performing an I/O operation.
Processor Management
In a multi-programming environment, the OS decides the order in which processes have access to the processor, and how much processing time each process has. This function of OS is called Process Scheduling. An Operating System performs the following activities for Processor Management.
Keeps track of the status of processes. The program which performs this task is known as a traffic controller. Allocates the CPU that is a processor to a process. De-allocates processor when a process is no more required.
In a multi-programming environment, the OS decides the order in which processes have access to the processor, and how much processing time each process has. This function of OS is called Process Scheduling. An Operating System performs the following activities for Processor Management.
Keeps track of the status of processes. The program which performs this task is known as a traffic controller. Allocates the CPU that is a processor to a process. De-allocates processor when a process is no more required.
Device Management
An OS manages device communication via its respective drivers. It performs the following activities for device management. Keeps track of all devices connected to the system. designates a program responsible for every device known as the Input/Output controller. Decides which process gets access to a certain device and for how long. Allocates devices effectively and efficiently. Deallocates devices when they are no longer required.
An OS manages device communication via its respective drivers. It performs the following activities for device management. Keeps track of all devices connected to the system. designates a program responsible for every device known as the Input/Output controller. Decides which process gets access to a certain device and for how long. Allocates devices effectively and efficiently. Deallocates devices when they are no longer required.
File Management
A file system is organized into directories for efficient or easy navigation and usage. These directories may contain other directories and other files. An Operating System carries out the following file management activities. It keeps track of where information is stored, user access settings, the status of every file, and more… These facilities are collectively known as the file system.
A file system is organized into directories for efficient or easy navigation and usage. These directories may contain other directories and other files. An Operating System carries out the following file management activities. It keeps track of where information is stored, user access settings, the status of every file, and more… These facilities are collectively known as the file system.
Network Management
The OS provides network connectivity and manages communication between computers on a network. It also manages network security by providing firewalls and other security measures.
The OS provides network connectivity and manages communication between computers on a network. It also manages network security by providing firewalls and other security measures.
Security
The operating system uses password protection to protect user data and similar other techniques. it also prevents unauthorized access to programs and user data.
Operating
System - Services
The operating system uses password protection to protect user data and similar other techniques. it also prevents unauthorized access to programs and user data.
An Operating System provides services to both the users and
to the programs.
·
It provides programs an environment to execute.
·
It provides users the services to execute the programs in a
convenient manner.
Following are a few common services provided by an
operating system −
·
Program execution
·
I/O operations
·
File System manipulation
·
Communication
·
Error Detection
·
Resource Allocation
·
Protection
Program
execution
Operating systems handle many
kinds of activities from user programs to system programs like printer spooler,
name servers, file server, etc. Each of these activities is encapsulated as a
process.
Operating system loads the
program into the memory after which it is executed. The order in which they are
executed depends on the CPU Scheduling Algorithms. Following are the major activities of an operating system
with respect to program management −
·
Loads a program into memory.
·
Executes the program.
·
Handles program's execution.
·
Provides a mechanism for process synchronization.
·
Provides a mechanism for process communication.
·
Provides a mechanism for deadlock handling.
I/O Operation
Operating System manages the
input-output operations and establishes communication between the user and
device drivers. Device drivers are software that is associated with hardware
that is being managed by the OS so that the sync between the devices works
properly.
·
I/O operation means read or write operation with any file or any
specific I/O device.
·
Operating system provides the access to the required I/O device
when need.
File system manipulation
A file system is normally
organized into directories for easy navigation and usage. These directories may
contain files and other directions. Following are the major activities of an
operating system with respect to file management −
·
Program needs to read a file or write a file.
·
The operating system gives the permission to the program for
operation on file.
·
Permission varies from read-only, read-write, denied and so on.
·
Operating System provides an interface to the user to
create/delete files.
·
Operating System provides an interface to the user to
create/delete directories.
·
Operating System provides an interface to create the backup of
file system.
Communication
The Operating system manages
the communication between processes. Communication between processes includes
data transfer among them. If the processes are not on the same computer but
connected through a computer network, then also their communication is managed
by the Operating System itself.
Following are the major
activities of an operating system with respect to communication −
·
Two processes often require data to be transferred between them
·
Both the processes can be on one computer or on different
computers, but are connected through a computer network.
·
Communication may be implemented by two methods, either by Shared
Memory or by Message Passing.
Error handling
Errors can occur anytime and
anywhere. An error may occur in CPU, in I/O devices or in the memory hardware.
Following are the major activities of an operating system with respect to error
handling −
·
The OS constantly checks for possible errors.
·
The OS takes an appropriate action to ensure correct and
consistent computing.
Resource Management
In case of multi-user or
multi-tasking environment, resources such as main memory, CPU cycles and files
storage are to be allocated to each user or job. Following are the major
activities of an operating system with respect to resource management −
·
The OS manages all kinds of resources using schedulers.
·
CPU scheduling algorithms are used for better utilization of CPU.
Protection
Considering a computer system
having multiple users and concurrent execution of multiple processes, the
various processes must be protected from each other's activities.
Protection refers to a
mechanism or a way to control the access of programs, processes, or users to
the resources defined by a computer system. Following are the major activities
of an operating system with respect to protection −
·
The OS ensures that all access to system resources is controlled.
·
The OS ensures that external I/O devices are protected from
invalid access attempts.
·
The OS provides authentication features for each user by means of
passwords.
No comments:
Post a Comment