OS Notes Unit 1
OS Notes Unit 1
OS STRUCTURE
Operating System structure is basically the model in which the system works.
The structure of the operating system should be user-friendly, such that if any
user having less knowledge about the system comes then he/she will not face
any difficulties while running the system.
COMPONENTS OF OPERATING SYSTEMS
1. Kernel:
The core of the operating system.
Manages essential system resources, such as CPU, memory, and I/O
devices.
Provides a bridge between application software and hardware.
2. Device Drivers:
Software modules that enable communication between the operating
system and hardware devices.
Facilitate the control and management of peripherals such as printers,
disk drives, and graphics cards.
3. File System:
Organizes and manages files on storage devices.
Provides a hierarchical structure of directories and files.
Manages file creation, deletion, and manipulation.
4. Process Management:
Controls the execution of processes (programs in execution).
Includes process creation, scheduling, and termination.
Manages process synchronization and communication.
5. Memory Management:
Allocates and deallocates memory space for processes.
Implements virtual memory to optimize the use of physical memory and
disk space.
6. Input/Output (I/O) System:
Manages communication between the CPU and external devices.
Includes I/O drivers and provides an interface for applications to perform
I/O operations.
7. User Interface:
Allows users to interact with the system.
Can be a command-line interface (CLI) or a graphical user interface (GUI).
8. Security and Access Control:
Enforces user authentication and authorization.
Controls access to resources and protects against unauthorized access.
9. Networking:
Manages communication between devices on a network.
Implements network protocols and services for data transfer and
resource sharing.
10. System Libraries:
Collections of pre-written code that provide common functionality to
applications.
Allow developers to use standardized functions without implementing
them from scratch.
11. Shell:
A command interpreter that allows users to interact with the operating
system using text commands.
Executes commands and provides a way for users to control and
customize the system.
12. Utilities:
System tools and programs that perform various tasks, such as disk
management, file compression, and system diagnostics.
Enhance the functionality of the operating system and assist users in
managing their systems.
KERNEL
The kernel is one of the components of the Operating System which works as a
core component. The rest of the components depends on Kernel for the supply
of the important services that are provided by the Operating System. The kernel
is the primary interface between the Operating system and Hardware.
Functions of Kernel
Types of Kernel
Monolithic Kernel
Microkernel
Hybrid Kernel
Exokernel
SHELL
Shell is the outermost layer of the Operating System and it handles the
interaction with the user.
The main task of the Shell is the management of interaction between the User
and OS.
Shell provides better communication with the user and the Operating System
Shell does it by giving proper input to the user it also interprets input for the
OS and handles the output from the OS.
32-Bit OS is required for running of 32- 64-Bit Processors can run on any of the
Bit Processors, as they are not capable Operating Systems, like 32-Bit OS or 64-
of running on 64-bit processors. Bit OS.
32-Bit Operating System can address 64-Bit Operating System can address
2^32 bytes of RAM. 2^64 bytes of RAM.
SYSTEM CALLS
System calls are interfaces or entry points through which applications or user-
level programs request services from the operating system's kernel.
These services can include operations such as file manipulation, process control,
and communication.
System calls allow applications to interact with the underlying hardware and
access various OS features in a controlled and secure manner.
TYPES OF SYSTEM CALLS
1. Process Control System Calls:
fork(): Create a new process by duplicating the existing process.
exec(): Replace the current process with a new one, loading a different
program into memory.
exit(): Terminate the current process and return its resources to the
system.
2. File Management System Calls:
open(): Open a file or create a new file if it does not exist.
close(): Close an open file descriptor.
read(): Read data from an open file.
write(): Write data to an open file.
seek(): Move the file pointer to a specific position in a file.
3. Device Management System Calls:
ioctl(): Perform I/O control operations on devices.
read(): Read data from a device.
write(): Write data to a device.
4. Information Maintenance System Calls:
getpid(): Get the process ID of the current process.
getuid(): Get the user ID of the current user.
5. Communication System Calls:
socket(): Create a communication endpoint for networking.
send(): Send data over a network socket.
recv(): Receive data over a network socket.
6. Memory Management System Calls:
brk(): Set the end of the data segment of the calling process to the
specified value.
sbrk(): Increment the program's data space (heap) by a specified number
of bytes.
mmap(): Map files or devices into memory.
munmap(): Unmap files or devices from memory.
7. Security System Calls:
chmod(): Change the permissions of a file.
chown(): Change the owner of a file.
8. Time System Calls:
time(): Get the current time in seconds since the epoch.
9. Signal Handling System Calls:
signal(): Set up signal handling for a process.
SYSTEM CALLS WORK
User need special resources : Sometimes programs need to do some
special things which can’t be done without the permission of OS like
reading from a file, writing to a file , getting any information from the
hardware or requesting a space in memory.
Program makes a system call request : There are special predefined
instruction to make a request to the operating system. These instruction
are nothing but just a “system call”. The program uses these system calls in
its code when needed.
Operating system sees the system call : When the OS sees the system call
then it recongnises that the program need help at this time so it
temporarily stop the program execution and give all the control to special
part of itself called ‘Kernel’ . Now ‘Kernel’ solve the need of program.
Operating system performs the operations :Now the operating system
perform the operation which is requested by program . Example : reading
content from a file etc.
Operating system give control back to the program : After performing the
special operation, OS give control back to the program for further
execution of program .
This type of operating system does not interact with the computer directly.
There is an operator which takes similar jobs having the same requirement
and groups them into batches. It is the responsibility of the operator to sort
jobs with similar needs.
It is very difficult to guess or know the time required for any job to
complete. Processors of the batch systems know how long the job would be
when it is in the queue.
Multiple users can share the batch systems.
The idle time for the batch system is very less.
It is easy to manage large work repeatedly in batch systems.
There is not any facility for user interaction of system resources with the
system.
Each task is given some time to execute so that all the tasks work smoothly.
Each user gets the time of the CPU as they use a single system. These systems
are also known as Multitasking Systems.
The task can be from a single user or different users also. The time that each
task gets to execute is called quantum. After this time interval is over OS
switches over to the next task.
Advantages of Time-Sharing OS
Disadvantages of Time-Sharing OS
Reliability problem.
One must have to take care of the security and integrity of user programs
and data.
Data communication problem.
High Overhead: Time-sharing systems have a higher overhead than other
operating systems due to the need for scheduling, context switching, and
other overheads that come with supporting multiple users.
Complexity: Time-sharing systems are complex and require advanced
software to manage multiple users simultaneously. This complexity
increases the chance of bugs and errors.
Security Risks: With multiple users sharing resources, the risk of security
breaches increases. Time-sharing systems require careful management of
user access, authentication, and authorization to ensure the security of
data and software.
Failure of one will not affect the other network communication, as all
systems are independent of each other.
Electronic mail increases the data exchange speed.
Since resources are being shared, computation is highly fast and durable.
Load on host computer reduces.
These systems are easily scalable as many systems can be easily added to
the network.
Delay in data processing reduces.
These systems run on a server and provide the capability to manage data,
users, groups, security, applications, and other networking functions. These
types of operating systems allow shared access to files, printers, security,
applications, and other networking functions over a small private network.
One more important aspect of Network Operating Systems is that all the users
are well aware of the underlying configuration, of all other users within the
network, their individual connections, etc. and that’s why these computers
are popularly known as tightly coupled systems.
These types of OSs serve real-time systems. The time interval required to
process and respond to inputs is very small. This time interval is
called response time.
Real-time systems are used when there are time requirements that are very
strict like missile systems, air traffic control systems, robots, etc.
Advantages 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 on.
Device driver and interrupt signals: It needs specific device drivers and
interrupts signal to respond earliest to interrupts.
Thread Priority: It is not good to set thread priority as these systems are
very less prone to switching tasks.
1. Number of Processors:
Single-Processor Systems:
Contain only one central processing unit (CPU).
Execute tasks sequentially, one at a time.
Multiprocessor Systems:
Have more than one CPU.
Enable parallel processing, where multiple tasks can be executed
simultaneously.
2. Concurrency:
Single-Processor Systems:
Execute tasks sequentially, leading to a lack of true concurrency.
Limited parallelism, as only one task is processed at a time.
Multiprocessor Systems:
Support true concurrency by allowing multiple tasks to be executed
in parallel.
Improved throughput and performance for parallelizable
workloads.
3. Task Scheduling:
Single-Processor Systems:
Task scheduling involves deciding which task to execute next on the
single CPU.
Limited to time-sharing or multitasking on a single processor.
Multiprocessor Systems:
More complex task scheduling to distribute tasks among multiple
processors.
Load balancing algorithms aim to distribute tasks evenly for optimal
resource utilization.
4. Resource Utilization:
Single-Processor Systems:
Limited to the capabilities of a single CPU.
Resource utilization may not be optimized for parallelizable
workloads.
Multiprocessor Systems:
Better resource utilization as tasks can be distributed among
multiple processors.
Improved scalability for handling increased workloads.
5. Memory Access:
Single-Processor Systems:
Typically use a single memory space.
Limited by the bandwidth of a single memory bus.
Multiprocessor Systems:
May have shared memory or distributed memory architectures.
Coordination is required to manage access to shared resources.
6. Cost and Complexity:
Single-Processor Systems:
Generally less expensive and less complex.
Simpler to design and manage.
Multiprocessor Systems:
Higher cost due to the additional hardware.
Increased complexity in terms of hardware and software design.
7. Scalability:
Single-Processor Systems:
Limited scalability in handling increasing workloads.
Performance improvement is constrained by the capabilities of a
single CPU.
Multiprocessor Systems:
Can be scaled by adding more processors to handle larger
workloads.
Potential for linear or near-linear performance improvement with
additional processors.
8. Fault Tolerance:
Single-Processor Systems:
Vulnerable to single points of failure.
Multiprocessor Systems:
Can be designed with redundancy for improved fault tolerance.
Some level of fault tolerance can be achieved through redundancy
and load balancing.
Running
Running Running multiple
Running multiple multiple tasks
multiple threads processes on
Definition programs on a (applications)
within a single multiple CPUs
single CPU on a single
task (application) (or cores)
CPU
Resources
Resources (CPU, Each process has
Resources (CPU, (CPU,
Resource memory) are its own set of
memory) are shared memory) are
Sharing shared among resources (CPU,
among programs shared among
threads memory)
tasks
PROCESS STATE
In an operating system, a process can exist in several states as it goes through its
lifecycle. The process state represents the current condition or stage of a process in
its execution. The different process states help the operating system manage and
control the execution of processes efficiently. Common process states include:
1. New:
The process is being created.
The operating system is initializing the necessary data structures for the
process.
2. Ready:
The process is prepared to execute but is waiting for the CPU to be
assigned to it.
Processes in the ready state are typically part of a pool of tasks awaiting
execution.
3. Running:
The process is actively being executed by the CPU.
In a multiprogramming system, multiple processes may be in the running
state simultaneously if there are multiple CPUs or if time-sharing is used.
4. Blocked (Waiting):
The process is not able to execute because it is waiting for some event to
occur.
Common scenarios leading to the blocked state include waiting for user
input, I/O operations, or completion of another process.
5. Terminated:
The process has finished its execution.
Resources allocated to the process, such as memory and system handles,
are released.
The process may communicate its exit status to the parent process or the
operating system.
COOPERATING PROCESS
Cooperating processes, also known as concurrent processes or concurrent threads,
are processes that can communicate and synchronize with each other to achieve a
common goal or to solve a particular problem. Cooperation between processes is
essential in scenarios where tasks need to be performed concurrently or where
collaboration is required. Here are some details about cooperating processes:
1. Shared Data:
Cooperating processes often share data or resources.
Shared data allows processes to exchange information and coordinate
their activities.
2. Inter-Process Communication (IPC):
IPC mechanisms enable communication between cooperating processes.
Common IPC mechanisms include shared memory, message passing,
semaphores, and pipes.
3. Reasons for Cooperation:
Speedup: Tasks can be performed concurrently, leading to faster overall
execution.
Modularity: Large problems can be divided into smaller, manageable
tasks that can be solved independently by cooperating processes.
Resource Sharing: Processes can share resources, such as files,
databases, or hardware devices.
4. Concurrency:
Cooperating processes execute concurrently, meaning they may overlap
in time.
Concurrent execution can lead to improved system responsiveness and
resource utilization.
5. Independent Execution:
Each cooperating process is typically an independent entity with its own
program counter, registers, and stack.
Processes may run independently, but they need to coordinate their
activities when interacting with shared data.
6. Synchronization:
Processes need synchronization mechanisms to avoid conflicts and
ensure the orderly execution of shared tasks.
Synchronization primitives like semaphores or mutexes help control
access to shared resources.
7. Communication Models:
Message Passing: Processes communicate by sending and receiving
messages. This can be either direct or through message-passing channels.
Shared Memory: Processes share a common, addressable memory space,
allowing them to read and write to shared variables.
8. Parallelism:
Cooperating processes can exploit parallelism to enhance system
performance.
Parallel execution of tasks can lead to improved throughput and reduced
execution time.
9. Examples:
Web servers: Multiple processes handling requests concurrently.
Database systems: Concurrent transactions accessing shared data.
Parallel computing: Splitting a computational task into multiple processes
for parallel execution.
10. Challenges:
Race Conditions: Conflicts that arise when multiple processes access
shared data concurrently.
Deadlocks: Situations where processes are unable to proceed because
they are waiting for each other to release resources.
Starvation: A process may be denied resources indefinitely, leading to its
inability to make progress.
THREADS
Thread refers to the smallest unit of execution within a process. Threads share
the same resources, such as memory space and file descriptors, while each
thread has its own program counter, register set, and stack.
Threads within the same process can communicate and share data more easily
than processes, which have more isolated memory spaces. Here are key details
about threads in operating systems:
1. Thread Characteristics:
Lightweight: Threads are generally lighter weight than processes,
requiring less overhead to create and switch between.
Independence: Threads within the same process operate independently
but share resources.
2. Types of Threads:
User-Level Threads (ULTs): Managed entirely by user-level libraries or
applications. The operating system is unaware of these threads.
Kernel-Level Threads (KLTs): Managed by the operating system kernel.
The kernel is aware of and manages these threads.
3. Multithreading Models:
Many-to-One Model (User-Level Threads): Many user-level threads map
to a single kernel-level thread. Thread management is handled entirely by
the user-level thread library.
One-to-One Model (Kernel-Level Threads): Each user-level thread
corresponds to one kernel-level thread. Thread management is handled
by the operating system.
4. Benefits of Multithreading:
Concurrency: Threads allow for concurrent execution of tasks within a
process.
Responsiveness: Multithreading can improve the responsiveness of
applications by allowing certain tasks to continue while others are waiting
for resources.
Parallelism: Threads enable parallelism, where multiple threads can
execute simultaneously on multi-core processors.
5. Thread States:
Running: The thread is actively executing on the CPU.
Ready: The thread is ready to execute but waiting for the CPU.
Blocked: The thread is waiting for an event, such as I/O completion.
Terminated: The thread has completed its execution.
1. Linux Kernel:
The core of the Linux operating system is the Linux kernel. It is
responsible for managing system resources, hardware interactions, and
providing essential services.
2. Open Source and Free Software:
Linux is distributed under the terms of the GNU General Public License
(GPL), making it open source and freely available for anyone to use,
modify, and distribute.
3. Distributions (Distros):
Linux is often distributed in the form of complete operating system
distributions, commonly known as distros.
Popular Linux distributions include Ubuntu, Debian, Fedora, CentOS, Arch
Linux, and many more.
Each distribution may have its own package management system, default
desktop environment, and configuration tools.
4. Package Management:
Most Linux distributions use a package management system to simplify
software installation, removal, and updates.
Common package managers include APT (Advanced Package Tool), YUM
(Yellowdog Updater, Modified), and Pacman.
5. Terminal and Command Line:
Linux is known for its powerful command-line interface (CLI), and users
can perform a wide range of tasks using the terminal.
The Bash shell is a common default shell in many Linux distributions.
6. User and Group Management:
Linux supports multi-user environments with user accounts and group
management.
Permissions and ownership of files and directories are crucial for security
and access control.
7. File System:
Linux uses various file systems, with ext4 being a common choice for
many distributions.
The file system hierarchy adheres to the Filesystem Hierarchy Standard
(FHS), which defines the directory structure and organization.
8. Networking:
Linux supports a wide range of networking protocols and services.
It is commonly used as a server operating system for web servers, file
servers, and networking infrastructure.
9. Security:
Linux has a strong security model with features such as user privileges,
file permissions, and security-enhanced Linux (SELinux).
Regular security updates are released by the Linux community to address
vulnerabilities.
1. Navigation:
ls: List files and directories.
cd: Change directory.
pwd: Print working directory.
2. File Management:
cp: Copy files or directories.
mv: Move or rename files or directories.
rm: Remove files or directories.
touch: Create an empty file.
3. Directory Operations:
mkdir: Create a new directory.
rmdir: Remove an empty directory.
rm -r: Remove a directory and its contents recursively.
4. Viewing Content:
cat: Display the content of a file.
more or less: Display content page by page.
head and tail: Display the beginning or end of a file.
5. File Editing:
nano or vim: Text editors for creating or editing files.
gedit: Graphical text editor.
6. File Permissions:
chmod: Change file permissions.
chown: Change file owner.
chgrp: Change file group.
7. User Management:
whoami: Display the current username.
passwd: Change user password.
useradd: Add a new user.
userdel: Delete a user.
su: Switch user.
8. Process Management:
ps: Display information about processes.
kill: Terminate a process.
top: Display dynamic, real-time system statistics.
9. System Information:
uname: Display system information.
hostname: Display or set the system hostname.
df: Display disk space usage.
du: Display file and directory space usage.
10. Networking:
ifconfig or ip: Display network interface information.
ping: Test network connectivity.
netstat: Display network statistics.
traceroute: Display the route packets take to reach a destination.
11. Package Management (package-based distributions):
apt (Debian/Ubuntu): Advanced Package Tool for package management.
yum (Red Hat/CentOS): Yellowdog Updater Modified for package
management.
12. Compression and Archiving:
tar: Create, extract, or view compressed or archived files.
gzip, bzip2, xz: Compress or decompress files.
13. Searching and Finding:
grep: Search for patterns in files.
find: Search for files and directories.
locate: Quickly find the location of files.
14. File System Operations:
mount: Mount a file system.
umount: Unmount a file system.
fdisk: Partition table manipulator.
15. System Shutdown/Reboot:
shutdown: Shutdown or restart the system.
reboot: Reboot the system.