0% found this document useful (0 votes)
8 views28 pages

Understanding Operating Systems and File Management

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views28 pages

Understanding Operating Systems and File Management

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Module 1

What is Operating System?


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.

What Operating Systems Do


We begin our discussion by looking at the operating system’s role in the overall computer
system. A computer system can be divided roughly into four components: the hardware, the
operating system, the application programs, and the users (Figure 1.1).
The hardware—the central processing unit (CPU), the memory,and the input/output (I/O)
devices—provides the basic computing resources for the system. The application programs—
such as word processors, spreadsheets,compilers, and Web browsers—define the ways in which
these resources are used to solve users’ computing problems. The operating system controls the
hardware and coordinates its use among the various application programs for the various users.
We can also view a computer system as consisting of hardware, software, and data. The
operating system provides the means for proper use of these resources in the operation of the
computer system. An operating system is similar to a government. Like a government, it
performs no useful function by itself. It simply provides an environment within which other
programs can do useful work.

Operating System - Examples1


There are plenty of Operating Systems available in the market which include paid and unpaid
(Open Source). Following are the examples of the few most popular Operating Systems:

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.

File Allocation Methods


The allocation methods define how the files are stored in the disk blocks. There are three main
disk space or file allocation methods.
Contiguous Allocation

Linked Allocation

Indexed Allocation

The main idea behind these methods is to provide:

Efficient disk space utilization.

Fast access to the file blocks.

All the three methods have their own advantages and disadvantages as discussed below:

1. Contiguous Allocation :In this scheme, each file occupies a contiguous set of blocks on
the disk. For example, if a file requires n blocks and is given a block b as the starting location,
then the blocks assigned to the file will be: b, b+1, b+2,......b+n-1. This means that given the
starting block address and the length of the file (in terms of blocks required), we can determine
the blocks occupied by the file. The directory entry for a file with contiguous allocation contains

Address of starting block

Length of the allocated portion.

The file 'mail' in the following figure starts from the block 19 with length = 6 blocks. Therefore,
it occupies 19, 20, 21, 22, 23, 24 blocks.
Advantages:
Both the Sequential and Direct Accesses are supported by this. For direct access, the address of
the kth block of the file which starts at block b can easily be obtained as (b+k).

This is extremely fast since the number of seeks are minimal because of contiguous allocation of
file blocks.

Disadvantages:
This method suffers from both internal and external fragmentation. This makes it inefficient in
terms of memory utilization.

Increasing file size is difficult because it depends on the availability of contiguous memory at a
particular instance.

2. Linked List Allocation In this scheme, each file is a linked list of disk blocks which
need not be contiguous. The disk blocks can be scattered anywhere on the disk. The directory
entry contains a pointer to the starting and the ending file block. Each block contains a pointer to
the next block occupied by the file. The file 'jeep' in following image shows how the blocks are
randomly distributed. The last block (25) contains -1 indicating a null pointer and does not point
to any other block.
Advantages:
This is very flexible in terms of file size. File size can be increased easily since the system does
not have to look for a contiguous chunk of memory.

This method does not suffer from external fragmentation. This makes it relatively better in terms
of memory utilization.

Disadvantages:
Because the file blocks are distributed randomly on the disk, a large number of seeks are needed
to access every block individually. This makes linked allocation slower.

It does not support random or direct access. We can not directly access the blocks of a file. A
block k of a file can be accessed by traversing k blocks sequentially (sequential access ) from the
starting block of the file via block pointers.

Pointers required in the linked allocation incur some extra overhead.

3. Indexed Allocation: In this scheme, a special block known as the Index block
contains the pointers to all the blocks occupied by a file. Each file has its own index block. The
ith entry in the index block contains the disk address of the ith file block. The directory entry
contains the address of the index block as shown in the image:

Advantages:
This supports direct access to the blocks occupied by the file and therefore provides fast access
to the file blocks.

It overcomes the problem of external fragmentation.

Disadvantages:
The pointer overhead for indexed allocation is greater than linked allocation.

For very small files, say files that expand only 2-3 blocks, the indexed allocation would keep one
entire block (index block) for the pointers which is inefficient in terms of memory utilization.
However, in linked allocation we lose the space of only 1 pointer per block.

Directory System
A directory is a container that is used to contain folders and files. It organizes files and folders in
a hierarchical manner. In other words, directories are like folders that help organize files on a
computer. Just like you use folders to keep your papers and documents in order, the operating
system uses directories to keep track of files and where they are stored. Different structures of
directories can be used to organize these files, making it easier to find and manage them.

Different Types of Directory in OS


In an operating system, there are different types of directory structures that help organize and
manage files efficiently.
Single-Level Directory
Two-Level Directory
Tree Structure/ Hierarchical Structure
Acyclic Graph Structure

1) Single-Level Directory
The single-level directory is the simplest directory structure. In it, all files are contained in the
same directory which makes it easy to support and understand.

A single level directory has a significant limitation, however, when the number of files increases
or when the system has more than one user. Since all the files are in the same directory, they
must have a unique name. If two users call their dataset test, then the unique name rule violated.

Single Level Directory

Advantages

Since it is a single directory, so its implementation is very easy.

If the files are smaller in size, searching will become faster.

The operations like file creation, searching, deletion, updating are very easy in such a directory
structure.

Disadvantages

There may chance of name collision because two files can have the same name.

Searching will become time taking if the directory is large.

This can not group the same type of files together.

2) Two-Level Directory
As we have seen, a single level directory often leads to confusion of files names among different
users. The solution to this problem is to create a separate directory for each user.

In the two-level directory structure, each user has their own user files directory (UFD). The
UFDs have similar structures, but each lists only the files of a single user. System's master file
directory (MFD) is searched whenever a new user id is created.

Advantages
The main advantage is there can be more than two files with same name, and would be very
helpful if there are multiple users.
A security would be there which would prevent user to access other user's files.
Searching of the files becomes very easy in this directory structure.
Disadvantages
As there is advantage of security, there is also disadvantage that the user cannot share the file
with the other users.
Unlike the advantage users can create their own files, users don't have the ability to create
subdirectories.
Scalability is not possible because one user can't group the same types of files together.

3) Tree Structure/ Hierarchical Structure


Tree directory structure of operating system is most commonly used in our personal computers.
User can create files and subdirectories too, which was a disadvantage in the previous directory
structures.

This directory structure resembles a real tree upside down, where the root directory is at the
peak. This root contains all the directories for each user. The users can create subdirectories and
even store files in their directory.

A user do not have access to the root directory data and cannot modify it. And, even in this
directory the user do not have access to other user's directories. The structure of tree directory is
given below which shows how there are files and subdirectories in each user's directory.

Advantages
This directory structure allows subdirectories inside a directory.
The searching is easier.
File sorting of important and unimportant becomes easier.
This directory is more scalable than the other two directory structures explained.
Disadvantages
As the user isn't allowed to access other user's directory, this prevents the file sharing among
users.
As the user has the capability to make subdirectories, if the number of subdirectories increase the
searching may become complicated.
Users cannot modify the root directory data.
If files do not fit in one, they might have to be fit into other directories.

4) Acyclic Graph Structure


As we have seen the above three directory structures, where none of them have the capability to
access one file from multiple directories. The file or the subdirectory could be accessed through
the directory it was present in, but not from the other directory.

This problem is solved in acyclic graph directory structure, where a file in one directory can be
accessed from multiple directories. In this way, the files could be shared in between the users. It
is designed in a way that multiple directories point to a particular directory or file with the help
of links.

What is File protection?


File protection in an operating system refers to the various mechanisms and techniques used to
secure files from unauthorized access, alteration, or deletion. It involves controlling access to
files, ensuring their security and confidentiality, and preventing data breaches and other security
incidents.
File Permissions: File permissions are a basic form of file protection that controls access to files
by setting permissions for users and groups. File permissions allow the system administrator to
assign specific access rights to users and groups, which can include read, write, and execute
privileges. These access rights can be assigned at the file or directory level, allowing users and
groups to access specific files or directories as needed. File permissions can be modified by the
system administrator at any time to adjust access privileges, which helps to prevent unauthorized
access.

Encryption : Encryption is the process of converting plain text into ciphertext to protect files
from unauthorized access. Encrypted files can only be accessed by authorized users who have
the correct encryption key to decrypt them. Encryption is widely used to secure sensitive data
such as financial information, personal data, and other confidential information. In an operating
system, encryption can be applied to individual files or entire directories, providing an extra
layer of protection against unauthorized access.

Access Control Lists (ACLs) : Access control lists (ACLs) are lists of permissions attached to
files and directories that define which users or groups have access to them and what actions they
can perform on them. ACLs can be more granular than file permissions, allowing the system
administrator to specify exactly which users or groups can access specific files or directories.
ACLs can also be used to grant or deny specific permissions, such as read, write, or execute
privileges, to individual users or groups.

Auditing and Logging : Auditing and logging are mechanisms used to track and monitor file
access, changes, and deletions. It involves creating a record of all file access and changes,
including who accessed the file, what actions were performed, and when they were performed.
Auditing and logging can help to detect and prevent unauthorized access and can also provide an
audit trail for compliance purposes.

Physical File Security: Physical file security involves protecting files from physical damage or
theft. It includes measures such as file storage and access control, backup and recovery, and
physical security best practices. Physical file security is essential for ensuring the integrity and
availability of critical data, as well as compliance with regulatory requirements.

What is Disk Scheduling Algorithm?


A Process makes the I/O requests to the operating system to access the disk. Disk Scheduling
Algorithm manages those requests and decides the order of the disk access given to the
[Link] scheduling is an important process in operating systems that determines the order
in which disk access requests are serviced. The objective of disc scheduling is to minimize the
time it takes to access data on the disk and to minimize the time it takes to complete a disk access
request. Disk access time is determined by two factors: seek time and rotational latency. Seek
time is the time it takes for the disk head to move to the desired location on the disk, while
rotational latency is the time taken by the disk to rotate the desired data sector under the disk
head. Disk scheduling algorithms are an essential component of modern operating systems and
are responsible for determining the order in which disk access requests are serviced. The primary
goal of these algorithms is to minimize disk access time and improve overall system
performance.

Why Disk Scheduling Algorithm is needed?


Disk Scheduling Algorithms are needed because a process can make multiple I/O requests and
multiple processes run at the same time. The requests made by a process may be located at
different sectors on different tracks. Due to this, the seek time may increase more. These
algorithms help in minimizing the seek time by ordering the requests made by the processes.

Important Terms related to Disk Scheduling Algorithms


Seek Time - It is the time taken by the disk arm to locate the desired track.
Rotational Latency - The time taken by a desired sector of the disk to rotate itself to the position
where it can access the Read/Write heads is called Rotational Latency.
Transfer Time - It is the time taken to transfer the data requested by the processes.
Disk Access Time - Disk Access time is the sum of the Seek Time, Rotational Latency, and
Transfer Time.

Disk Scheduling Algorithms


[Link]-Come-First-Serve
The First-Come-First-Served (FCFS) disk scheduling algorithm is one of the simplest and most
straightforward disk scheduling algorithms used in modern operating systems. It operates on the
principle of servicing disk access requests in the order in which they are received. In the FCFS
algorithm, the disk head is positioned at the first request in the queue and the request is serviced.
The disk head then moves to the next request in the queue and services that request. This process
continues until all requests have been serviced.

Example
Suppose we have an order of disk access requests: 20 150 90 70 30 60. The disk head is ?

currently located at track 50.

The total seek time = (50-20) + (150-20) + (150-90) + (90-70) + (70-30) + (60-30) = 310

[Link]-Seek-Time-First
Shortest Seek Time First (SSTF) is a disk scheduling algorithm used in operating systems to
efficiently manage disk I/O operations. The goal of SSTF is to minimize the total seek time
required to service all the disk access requests. In SSTF, the disk head moves to the request with
the shortest seek time from its current position, services it, and then repeats this process until all
requests have been serviced. The algorithm prioritizes disk access requests based on their
proximity to the current position of the disk head, ensuring that the disk head moves the shortest
possible distance to service each request.

Example

In this case, for the same order of success request, the total seek time = (60-50) + (70-60) + (90-
70) + (90-30) + (30-20) + (150-20) = 240

[Link]
SCAN (Scanning) is a disk scheduling algorithm used in operating systems to manage disk I/O
operations. The SCAN algorithm moves the disk head in a single direction and services all
requests until it reaches the end of the disk, and then it reverses direction and services all the
remaining requests. In SCAN, the disk head starts at one end of the disk, moves toward the other
end, and services all requests that lie in its path. Once the disk head reaches the other end, it
reverses direction and services all requests that it missed on the way. This continues until all
requests have been serviced.

Example

If we consider that the head direction is left in case of SCAN, the total seek time = (50-30) + (30-
20) + (20-0) + (60-0) + (60-70) + (90-70) + (90-150) = 200

4.C-SCAN
The C-SCAN (Circular SCAN) algorithm operates similarly to the SCAN algorithm, but it does
not reverse direction at the end of the disk. Instead, the disk head wraps around to the other end
of the disk and continues to service requests. This algorithm can reduce the total distance the
disk head must travel, improving disk access time. However, this algorithm can lead to long wait
times for requests that are made near the end of the disk, as they must wait for the disk head to
wrap around to the other end of the disk before they can be serviced. The C-SCAN algorithm is
often used in modern operating systems due to its ability to reduce disk access time and improve
overall system performance.

Example
For C-SCAN, the total seek time = (60-50) + (70-60) + (90-70) + (150-90) + (199-150) + (199-0)
+ (20-0) + (30-20) = 378

[Link]
The LOOK algorithm is similar to the SCAN algorithm but stops servicing requests as soon as it
reaches the end of the disk. This algorithm can reduce the total distance the disk head must
travel, improving disk access time. However, this algorithm can lead to long wait times for
requests that are made near the end of the disk, as they must wait for the disk head to wrap
around to the other end of the disk before they can be serviced. The LOOK algorithm is often
used in modern operating systems due to its ability to reduce disk access time and improve
overall system performance.

Example
Considering the head direction is right, in this case, the total seek time = (60-50) + (70-60) + (90-
70) + (150-90) + (150-30) + (30-20) = 230
6.C-LOOK
C-LOOK is similar to the C-SCAN disk scheduling algorithm. In this algorithm, goes only to the
last request to be serviced in front of the head in spite of the disc arm going to the end, and then
from there it goes to the other end's last request. Thus, it also prevents the extra delay which
might occur due to unnecessary traversal to the end of the disk.

Example
For the C-LOOK algorithm, the total seek time = (60-50) + (70-60) + (90-70) + (150-90) + (150-
20) + (30-20) = 240

Disk Management
Partitioning the Disk:

Divides a physical disk into logical sections called partitions.


Each partition can be treated as a separate disk by the OS.

Formatting the Disk:

Prepares a partition to store data by setting up a file system.


Creates structures like the File Allocation Table (FAT), root directory, etc.
Ensures compatibility with the OS and file access.
Mounting and Unmounting:

Mounting makes a file system accessible to the OS (e.g., showing a drive in Windows Explorer).
Unmounting safely disconnects a storage device.

File System Management:

Organizes and controls how data is stored and retrieved.


Supports file operations: create, delete, read, write, rename, etc.

Free Space Management:

Tracks unused disk space.


Uses bitmaps, linked lists, or grouping to manage free blocks.

Disk Scheduling:

Determines the order in which disk I/O requests are processed.


Improves efficiency by reducing seek time.
Algorithms: FCFS, SSTF, SCAN, C-SCAN, LOOK, etc.

Bad Block Management:

Detects and handles defective sectors on the disk.


Replaces or avoids bad blocks using spare sectors or logical remapping.
Disk Quota Management:

Restricts how much disk space a user or group can use.


Prevents misuse and ensures fair resource allocation.

Data Integrity and Recovery:

Ensures file system consistency after crashes.


Uses journaling or backup logs to recover lost data.

Linux History
Linus Torvalds designed the free and open-source Linux operating system kernel in 1991,
inspired by the UNIX operating system and the MINIX operating system. His goal was to build a
flexible and affordable platform for personal computing. The initial release of the Linux kernel
quickly drew global attention from developers and enthusiasts, encouraging collaborative
development. Over time, this led to the creation of complete Linux distributions, powered by the
kernel and supported by open-source software packages.

Why use Linux?


Because it is free, open-source, and extremely flexible, Linux is widely utilized. For servers and
developers, it is the ideal option because it offers strong security, stability, and performance.
Generally interoperable hardware, a broad software library, and a vibrant community that offers
support and regular updates are the many benefits of Linux. Due to its adaptability, users can
customize the operating system according to their own needs, whether they become for personal
or large enterprise use.

Architecture of Linux
1. Kernel
Kernel is the main core component it is lies between the shell and the hardware. It controls the
activity of other hardware components. It visualizes the common hardware resources and provide
each process with necessary virtual resources. It makes the process to wait in the ready queue
and execute in consequently to avoid any kind of conflict.

The kernel is software that manages communication between the hardware and the system. It
cannot directly interact with directories or files. Instead, the kernel handles the communication
between the computer system and the hardware.

The kernel is responsible for:

Memory management: Manages and allocates memory efficiently.


Resource allocation: Distributes system resources to different processes.
Device management: Controls input/output devices like printers and scanners.
Process management: Manages process execution and scheduling.
Application interaction: Bridges applications with system-level functions.
Security: Provides essential system-level security.

Different of types of kernel


There are several kernel types

1. Monolithic Kernel

A Monolithic kernel is an operating system kernel where all concurrent processes run
simultaneously within the kernel itself, sharing the same memory resources.
2. Micro kernel

In micro kernel user services and kernel services are executed in separate address spaces. User
services are kept in user address space and kernel services are kept in kernel address space. This
architecture means dependencies are not embedded directly within the kernel, instead,
applications must install and manage their own.
3. Exokernel

Exo-kernel is designed to manage hardware resources at application level. High level abstraction
is used in this operating system to offer hardware resources access to kernel.

4. Hybrid kernel

It is the combination of both monolithic kernel and microkernel. Windows uses a Hybrid Kernel.
It supports system-level performance like a Monolithic kernel while offering the modular design
of Microkernels.

System Library: Linux uses system libraries, also known as shared libraries, to implement
various functionalities of the operating system. These libraries contain pre-written code that
applications can use to perform specific tasks. By using these libraries, developers can save time
and effort, as they don't need to write the same code repeatedly. System libraries act as an
interface between applications and the kernel, providing a standardized and efficient way for
applications to interact with the underlying system.
Shell: The shell is the user interface of the Linux Operating System. It allows users to interact
with the system by entering commands, which the shell interprets and executes. The shell serves
as a bridge between the user and the kernel, forwarding the user's requests to the kernel for
processing. It provides a convenient way for users to perform various tasks, such as running
programs, managing files, and configuring the system.
Hardware Layer: The hardware layer encompasses all the physical components of the
computer, such as RAM (Random Access Memory), HDD (Hard Disk Drive), CPU (Central
Processing Unit), and input/output devices. This layer is responsible for interacting with the
Linux Operating System and providing the necessary resources for the system and applications
to function properly. The Linux kernel and system libraries enable communication and control
over these hardware components, ensuring that they work harmoniously together.
System Utility: System utilities are essential tools and programs provided by the Linux
Operating System to manage and configure various aspects of the system. These utilities perform
tasks such as installing software, configuring network settings, monitoring system performance,
managing users and permissions, and much more. System utilities simplify system
administration tasks, making it easier for users to maintain their Linux systems efficiently.

Basic Commands In Linux

While learning Linux, the basic thing which you will learn are the Linux commands. Linux
commands are the directions given by the users to the computer to perform a particular task.
Create Directory - Example
For example if a user wants to create a directory then following mkdir is the command to create a
directory in Linux:
# Command to create directory in Linux
$ mkdir testing
Change Directory - Example
If a user wants to go inside a particular directory then following is the command to change the
directory in Linux:
# Command to change the directory in Linux
$ cd testing
This cd Linux command will take you inside testing directory.
List Directory - Example
Following is the command list down all the files and sub-directories available in the current
directory in Linux:
# Command to list the content inside a directory in Linux
$ ls -l
pwd Command
The pwd command is used to display the location of the current working directory
$ pwd
/home/os/
rm command in Linux
rm command in Linux is generally used to delete the files created in the directory.

Command:

Output

mv command in Linux
The mv command is generally used for renaming the files in Linux.
Command:
output

cp command in Linux
The cp command of Linux is equivalent to copy-paste and cut-paste in Windows.
Command:

output

Here we used ls to view the files and then used cp to copy the files of [Link] to [Link] and
again used ls command to view the updated files.
locate command in Linux
The locate command is generally used to locate the files in the database. Use an asterisk (*) to
search for content that contains two or more words. As an example: locate first*file. This
command will search the database for the files that contain these two names first and file.
Command:

output

We first used the rm command to delete the file and then used the locate command to find the
file in the database which in return has given the output with a -e as the file was removed.
touch command in Linux
The touch command creates an empty file when put in the terminal in this format as touch <file
name>
We used the ls command to check the current directories in the terminal and then used the touch
command to create an empty file and then again we used ls to find out the created file in the
terminal.

cat command in Linux


The cat command is the simplest command to use when you want to see the contents of a
particular file. The only issue is that it simply unloads the entire file to your terminal. If you want
to navigate around a huge file, should use less command alternatively.

Command:

output

man command in Linux


The man command displays a user manual for any commands or utilities available in the
Terminal, including their name, description, and options.

Command to view the full manual:

man <command name>


For example, suppose you want to look up the manual for the ls command: man ls

output
echo command in Linux
echo command in Linux is specially used to print something in the terminal

paste Command
Used to merge lines from two or more files line by line.

Syntax:
paste [OPTION]... [FILE1] [FILE2]...
Common Options:
-d: Specify delimiter to separate columns (default is Tab)

-s: Paste serially (combine lines one after another instead of line by line)

Example : Merge two files line by line


[Link]:
John
Anita
Ravi
[Link]:
Engineer
Doctor
Teacher
To combine both:
paste -d ',' [Link] [Link]
Output:
John,Engineer
Anita,Doctor
Ravi,Teacher

You might also like