UNIT 1os
UNIT 1os
Concept of os :
An Operating System (OS) is an interface between a computer user and computer hardware.
An operating system is a software which performs all the basic tasks like file management,
memory management, process management, handling input and output, and controlling
peripheral devices such as disk drives and printers.
If we consider a Computer Hardware is body of the Computer System, then we can say an
Operating System is its soul which brings it alive ie. operational. We can never use a
Computer System if it does not have an Operating System installed on it.
EXAMPLES-
Windows: This is one of the most popular and commercial operating systems
developed and marketed by Microsoft. It has different versions in the market like
Windows 8, Windows 10 etc and most of them are paid.
Linux This is a Unix based and the most loved operating system first released on
September 17, 1991 by Linus Torvalds. Today, it has 30+ variants available like Fedora,
OpenSUSE, CentOS, UBuntu etc. Most of them are available free of charges though
you can have their enterprise versions by paying a nominal license fee.
MacOS This is again a kind of Unix operating system developed and marketed by
Apple Inc. since 2001.
iOS This is a mobile operating system created and developed by Apple Inc. exclusively
for its mobile devices like iPhone and iPad etc.
Android This is a mobile Operating System based on a modified version of the Linux
kernel and other open source software, designed primarily for touchscreen mobile
devices such as smartphones and tablets.
FUNCTIONS
Process Management
I/O Device Management
File Management
Network Management
Main Memory Management
Secondary Storage Management
Security Management
Command Interpreter System
Control over system performance
Job Accounting
Error Detection and Correction
Coordination between other software and users
TYPES OF OS
Types of Operating Systems
Operating Systems can be categorized according to different criteria like whether an
operating system is for mobile devices (examples Android and iOS) or desktop (examples
Windows and Linux).
8 Main Operating System Types: Categorized by Purpose and Functionality
Batch Operating System
Multi-Programming Operating System
Multi-Processing Operating System
Multi-User Operating Systems
Distributed Operating System
Network Operating System
Real-Time Operating System
Mobile Operating Systems
1. Batch Operating System
Batch processing was quite popular in the 1970s. Similar types of jobs have been
batched together and completed on time using this method.
Now, more than one individual can have access to this Operating System, and they
can submit their jobs to the system for execution. The system places all of the jobs
in a queue, first come, first served, and then executes them one at a time. When all
of the jobs are completed, the users receive their respective outputs.
Advantages of Batch Operating System
Multiple users can share the batch systems.
The idle time for the batch system is very little.
It is easy to manage large work repeatedly in batch systems.
Disadvantages of Batch Operating System
CPU is not used efficiently. When the current process is doing IO, the CPU is free and
could be utilized by other processes waiting.
The other jobs will have to wait for an unknown time if any job fails.
In a batch operating system, average response time increases as all processes are
processed one by one.
Examples of Batch Operating Systems: Payroll Systems, Bank Statements, etc.
2 Multi-Programming Operating System
Multiprogramming Operating Systems can be simply illustrated as more than one program is
present in the main memory and any one of them can be kept in execution. This is used for
better utilization of resources.
Advantages of, Multi-Programming Operating System
CPU is better utilized, and the overall performance of the system improves.
It helps in reducing the response time.
Disadvantages:
Potential for Long Waits:
k
Long-term jobs may experience longer wait times due to being switched out of the CPU
while other, shorter jobs are executed.
Tracking and Management Complexity:
Managing multiple concurrently running processes can be complex, requiring careful
scheduling and memory management.
Scheduling Implementation:
Implementing efficient CPU scheduling can be challenging.
No Direct User Interaction:
There is no direct user interaction with the program while it is in the execution phase.
Example: Imagine a computer running a text editor, a web browser, and a music player
simultaneously. The multiprogramming OS can switch rapidly between these tasks, allowing
the user to work on the text editor, browse the web, and listen to music without noticing a
significant performance slowdown.
3. Multiprocessing Operating System
Multiprocessing helps in performing parallel computing. There are several processors in a
system, each of which can run multiple processes at the same time. The system’s throughput
will be significantly increased as a result of this.
Parallel computing is performed by multiprocessing. The presence of more than one
processor in the system allows it to run multiple processes at the same time, increasing the
system’s throughput. Read more on Multiprocessing Operating System here.
Advantages of a Multi-User Operating System
It increases the throughput of the system as processes can be parallelized.
As it has several processors, so, if one processor fails, we can proceed with another
processor.
Disadvantages:
Increased complexity:
Multiprocessing operating systems are more complex than single-processor systems,
requiring specialized algorithms for process synchronization and load balancing. This
complexity can lead to increased development and maintenance costs.
Resource contention:
When multiple processors access shared resources, there can be potential for resource
contention, where one processor's actions can negatively impact others.
Debugging challenges:
Debugging multiprocessing systems can be more challenging than debugging single-
processor systems, as it requires identifying and resolving issues across multiple processors.
Increased memory requirements:
Multiprocessing systems may require more memory than single-processor systems, as each
processor needs its own memory space.
4. Multitasking Operating System
The multitasking OS refers to a logical extension of the multiprogramming Operating System,
which allows users to run many programs at the same time. It enables a user to complete
multiple computer tasks at the same time.
Types of Multi-Tasking Operating System
1. Preemptive Multitasking Operating System
k Advantages of RTOS
Maximum Consumption: Maximum utilization of devices and systems, thus more
output from all the resources.
Task Shifting: The time assigned for shifting tasks in these systems is very less. For
example, in older systems, it takes about 10 microseconds to shift from one task to
another, and in the latest systems, it takes 3 microseconds.
Focus on Application: Focus on running applications and give less importance to
applications that are in the queue.
Real-time operating system in the embedded system: Since the size of programs is
small, RTOS can also be used in embedded systems like in transport and others.
Error-Free,: These types of systems are error-free.
Memory Allocation: Memory allocation is best managed in these types of systems.
Disadvantages of RTOS
Limited Tasks: Very few tasks run at the same time and their concentration is very
less on a few applications to avoid errors.
Use heavy system resources: Sometimes the system resources are not so good and
they are expensive as well.
Complex Algorithms: The algorithms are very complex and difficult for the designer
to write.
Device driver and interrupt signals: It needs specific device drivers and interrupt
signals to respond earliest to interrupts.
Thread Priority: It is not good to set thread priority, as these systems are much less
prone to switching tasks.
Examples of Real-Time Operating Systems are Scientific experiments, medical imaging
systems, industrial control systems, weapon systems, robots, air traffic control systems, etc.
8. Mobile Operating Systems
Mobile operating systems are designed specifically for mobile devices such as smartphones
and tablets. Examples of such operating systems are Android and iOS. These operating
systems manage the hardware and software resources of the device, providing a platform
for running applications and ensuring a seamless user experience.
Advantages of Mobile Operating Systems
User-Friendly Interfaces: Mobile operating systems are designed to be intuitive and easy to
use, making them accessible to a wide range of users.
Extensive App Ecosystems: The availability of a vast number of applications allows users to
customize their devices to meet their specific needs.
Connectivity Options: Mobile operating systems support multiple connectivity options,
enabling users to stay connected wherever they go.
Regular Updates: Mobile operating systems receive regular updates, including new features,
security patches, and performance improvements.
Disadvantages Mobile Operating Systems
Battery Life Constraints: Despite advancements in power management, battery life remains
a challenge for mobile devices, especially with heavy usage.
Security Risks: Mobile devices are susceptible to various security threats, such as malware
and phishing attacks, which can compromise user data.
Fragmentation: In the case of Android, the wide range of devices and customizations can
lead to fragmentation, making it difficult for developers to ensure compatibility across all
devices.
Limited Hardware Resources: Mobile devices have limited processing power, memory, and
storage compared to desktop computers, which can affect the performance of resource-
intensive applications.
Operating System Services
The operating system provides services to both the user and the programs running in the
system. The operating system itself is a program that provides an environment to run other
programs in the system. To the user, the operating system provides various services to run
multiple user processes in the system. Operating system services such as process
management, memory management, and resource allocation management are provided by
the operating system.
Program execution
Control Input/output devices
Program creation
Error Detection and Response
Accounting
Security and Protection
File Management
Communication
User Interface
Resource allocation
Command interpretation
Program execution
The operating system loads the program into the memory and takes care of the
memory allocation for the program. Program execution is one of the operating
system services which also ensures that the program that is started can also end its
execution either normally or forcefully.
The program is first loaded into the RAM and then the CPU is being assigned for
program execution through various CPU scheduling algorithms provided by the
operating system.
After the program execution, the operating system also takes care of
process synchronization, inter-process communication, and deadlock handling.
Control Input/output devices
The programs running in the system need input and output devices access for
performing the input/output operations. The access to the input and output devices
is given by the operating system to the program for I/O operations.
I/O operations mean writing or reading operations performed over any file or any
input/output device.
Program creation
In order to create, modify and debug programs the operating system provides tools
like editors and debuggers to make the task of programmers easy.
Error Detection and Response
Handling and detecting error is one of the crucial operating system services which
ensures the smooth working of the system.
The error can occur in the system in the following devices or programs -
Network connection error, loose connection of I/O devices, and restricted network
calls are some of the error that occur in input/output devices.
The program run by the user in the system can also cause errors such as accessing
illegal memory, undefifned operations such as division by zero, excess use of CPU by
a program etc.
Accounting
The operating system keeps track of all the data of performance parameters and
response time of the system in order to make it more robust. This data is used to
improve the performance of the operating system and minimize the response time of
the system.
Security and Protection
If a user downloads a program from the internet there are chances that the program
can contain malicious code which can affect other programs in the system. The
operating system takes care that such a program is checked for any malicious
code before downloading it to the system.
File Management
File management is one of the operating system services that handles the memory
management for the programs running in the system.
The operating system knows the information of all the types of different files and
properties of different storage devices and ensures the proper management and
safety of the files stored in the secondary storage devices.
Communication
The processes running in the system need to communicate with each other and also
the computers or systems connected over a network need to exchange data with
each other over a secure network. Operating system uses message passing and
shared memory to keep communication effective and safe.
User Interface
The user interacts with the system either by command-line interface or Graphical
user interface.
The command-line interface uses text commands entered by the user to interact with
the system. These commands can also be given using a terminal emulator, or remote
shell client.
A graphical user interface is a more user-friendly way to interact with the system. The
GUI provides icons, widgets, texts, labels, and text navigation. The user can easily
interact with these icons and widgets with just a click of a mouse or keyboard.
Resource allocation
The processes running in the system require resources to complete their execution.
The operating system uses CPU scheduling to allocate resources effectively among
the processes ensuring better utilization of the CPU.
The resources used by the processes can be CPU cycles, primary memory storage, file
storage, and I/O devices.
Command Interpretation
The user interacts with the system through commands and the operating system
interprets these commands and inputs and provides appropriate outputs accordingly.
If the interpreter is separate from the kernel then the user can modify the interpreter
and prevent any unauthorized access to the system.
Conclusion
In conclusion, the operating system provides a plethora of services that are essential
for the smooth and efficient functioning of a computer system.
These services include program execution, input/output device control, program
creation, error detection and response, accounting, security and protection, file
management, communication, user interface, resource allocation, and command
interpretation.
By providing these services, the operating system acts as a bridge between the user
and the hardware, making it possible for users to interact with the computer system
in a meaningful way.
SYSTEM CALLS
When the process is being run, if the process requires certain actions that need to be
carried out by Operating System, the process has to go call the function which can
interact with the kernel to complete the actions. This special type of function call is
known as System Calls in OS. System calls provide the interface so that the process
can communicate with the Operating System.
k
n our computer system, we have two modes available.
1. User Mode: In this mode, execution is done on behalf of the user.
2. Monitor/Kernel-Mode: In this mode, execution is done on behalf of OS.
k
3. So when the process is under execution process executes under user mode,
but when the process requires some OS resources to complete the task, the
process makes a system call.
4. System calls in OS are executed in kernel mode on a priority basis.
5. On completion of the system call, the control is passed to process in user
mode.
6. The process continues the execution in user mode.
Types of System Calls in OS
There are mainly 5 types of system calls available:
Process Control
File Management
Device Management
Information Maintenance
Communication
K
1. Process Control: It handles the system calls for process creation, deletion, etc.
Examples of process control system calls are: Load, Execute, Abort, and Wait for
Signal events for process.
2. File Management: File manipulation events like Creating, Deleting, Reading
Writing etc are being classified under file management system calls.
3. Device Management: Device Management system calls are being used to request
the device, release the device, and logically attach and detach the device.
4. Information Maintenance: This type of system call is used to maintain the
information about the system like time and date.
5. Communications: In order to have interprocess communications like send or receive
the message, create or delete the communication connections, to transfer status
information etc. communication system calls are used.
Important System Calls Used in OS
1. wait(): There are scenarios where the current process needs to wait for another
process to complete the task. So to wait in this scenario, wait() system call is used.
2. fork(): This system call creates the copy of the process that has called it. The one
which has called fork is called the parent process and the newly created copy is
called the child process.
3. exec(): This system call is called when the running process wants to execute another
executable file. The process id remains the same while the other resources used by
the process are replaced by the newly created process.
4. kill(): Sometimes while working, we require to terminate a certain process. So kill
system call is called which sends the termination signal to the process.
5. exit(): When we are actually required to terminate the program, an exit system call is
used. The resources that are occupied by the process are released after invoking the
exit system call.
4. CPU registers: The content of processor registers gets stored here when the
process is in running state. The different kinds of CPU registers are
accumulators, index and general-purpose registers, instruction register and
condition code register.
5. CPU scheduling information: A process needs to be scheduled for
execution. Based on this scheduling, it goes from ready to running. CPU
Scheduling information contains process priority (to determine which
process goes first), pointers for scheduling queues (to mark the order of
execution), and various other scheduling parameters.
6. Accounting and business information: Contains details like CPU
utilization, real-time used by the process, number of jobs or processes, etc.
7. Memory-management information: Contains value of base and limit
registers, details about page and segment tables. It depends on the memory
system of the OS in use.
8. I/O status information: Comprises I/O related information including list of
I/O devices allocated to the process, status, etc.
Process States
The following are the process states in an operating system:
1. New: When a program is started, the operating system creates a new process for it.
The process is then placed in the new state. In the new state, the process has been
created but has not yet been allocated any resources.
2. Runnable: When a process is in the runnable state, it is ready to be executed. The
operating system maintains a queue of runnable processes. The scheduler selects a
process from the queue and moves it to the running state.
3. Running: When a process is in the running state, it is currently being executed. The
process has been given the CPU and is executing its instructions.
4. Blocked: When a process is in the blocked state, it is waiting for an event to occur.
The event could be the completion of an I/O operation, the arrival of a signal, or the
availability of a resource. When the event occurs, the process is moved to the
runnable state.
Components of Thread
A thread has the following three components:
1. Program Counter
2. Register Set
3. Stack space
Stack Space: Stores local variables, function calls, and return addresses specific to
the thread.
Register Set: Hold temporary data and intermediate results for the thread’s
execution.
Program Counter: Tracks the current instruction being executed by the thread.
Types of Thread
1. User Level Thread:
User-level threads are implemented and managed by the user and the kernel is not aware of
it.
User-level threads are implemented using user-level libraries and the OS does not
recognize these threads.
User-level thread is faster to create and manage compared to kernel-level thread.
Context switching in user-level threads is faster.
If one user-level thread performs a blocking operation then the entire process gets
blocked. Eg: POSIX threads, Java threads, etc.
2. Kernel level Thread:
Kernel level threads are implemented and managed by the OS.
Kernel level threads are implemented using system calls and Kernel level threads
are recognized by the OS.
Kernel-level threads are slower to create and manage compared to user-level
threads.
Context switching in a kernel-level thread is slower.
Even if one kernel-level thread performs a blocking operation, it does not affect other
threads. Eg: Window Solaris.
Advantages of Threading
Threads improve the overall performance of a program.
Threads increases the responsiveness of the program
Context Switching time in threads is faster.
Threads share the same memory and resources within a process.
Communication is faster in threads.
Threads provide concurrency within a process.
Enhanced throughput of the system.
Since different threads can run parallelly, threading enables the utilization of the
multiprocessor architecture to a greater extent and increases efficiency.
Key characteristics of threads:
Lightweight:
Threads are generally considered lighter than processes, meaning they require fewer
resources to create and manage.
Concurrent execution:
Multiple threads within the same process can execute concurrently, allowing for parallel
processing and improved performance.
Shared resources:
Threads within the same process share the same memory space, allowing them to
communicate and access data easily.
Independent execution:
Each thread has its own program counter, stack, and other execution-related resources,
allowing it to execute independently.
Scheduling:
Threads are scheduled by the operating system to execute on the CPU.
Thread States in Operating Systems
(1) Ready
(2) Running
(3) Waiting
(4) Delayed
(5) Blocked