Operating System Notes

C
DSA
Software Engineering
Software Architecture
Operating System
Big Data
Data Mining and Warehousing
TOC
Ada
CPP
DBMS

All Topics (20)

  • 1. Definition of Operating System
  • 2. Primary Objectives of an Operating System
  • 3. Functions of an Operating System
  • 4. Services of an Operating System
  • 5. Types of Operating System
  • 6. Serial Processing System / Bare Machine
  • 7. Simple Batch System
  • 8. Multiprogramming Operating System
  • 9. Time Sharing System / Multitasking System
  • 10. Multiprocessor System
  • 11. Network Operating System (NOS)
  • 12. Real-Time Operating System (RTOS)
  • 13. System Calls
  • 14. Utility Programs
  • 15. File Management
  • 16. File Attributes
  • 17. File Operations
  • 18. Types of Files
  • 19. Directories
  • 20. Access Methods in File System

16. File Attributes

Whenever a file is saved on a hard disk, the operating system associates several attributes with it:

1. Name

Every file has a name used to identify and perform operations on it.
Example: a.txt, report.docx

2. Identifier

When a file is created, the operating system assigns a unique number to it internally.
This number is used by the OS to perform operations on the file.

3. Type

This specifies the kind of file.
Different file types include:

  • Text file (.txt)
  • PowerPoint file (.ppt)
  • C++ file (.cpp)
  • Word file (.docx)

File extension is used to indicate the file type.

4. Location

This shows the path where the file is stored on the hard disk.

Example:
C:\Program Files\Microsoft Word\a.docx

5. Size

This represents the size of the file in bytes, kilobytes (KB), megabytes (MB), etc.

Example:
a.txt → 10 KB

6. Protection

This defines access permissions for the file. There are three main types:

  • Read (R) – allows reading the file
  • Write (W) – allows modifying the file
  • Execute (X) – allows running the file

These permissions are given to users based on user ID, time, and access rules.

7. Date

This records timestamps of the file:

  • Creation time
  • Last modified time
  • Last accessed time

Example Summary

Attribute Example Value
Name a.txt
Size 10 KB
Identifier 12345
Type Text file
Location C:\Program Files\App\a.txt
Protection R, W, X
Date Created & Modified time

 

17. File Operations

File operations are actions performed by the operating system on files using system calls.

1. Create (create())

To create a new file, the OS allocates space on the disk and makes an entry in the directory.

Example:
You create a file named notes.txt.

  • OS allocates space on disk
  • Adds entry in directory: notes.txt

2. Open

Before using a file, it must be opened. The OS searches the directory and loads the file entry into the open-file table.

Example:
Opening notes.txt in Notepad:

  • OS finds file in directory
  • Loads it for editing

3. Close

After finishing work, the file is closed and removed from the open-file table.

Example:
After editing notes.txt, you click Save & Close:

  • File entry removed from memory table
  • File is safely saved

4. Write

Used to add or modify data in a file.

Example:
Writing in notes.txt:

Hello World
  • OS writes data at current write pointer position

5. Read

Used to read data from a file.

Example:
Opening notes.txt to view content:

  • OS reads data from file
  • Displays “Hello World”

6. Reposition (Seek)

Moves the file pointer to a specific location in the file.

Example:
In a 100-line file, you jump directly to line 50:

  • OS moves pointer to line 50
  • No reading of previous lines needed

7. Delete

Removes the file completely from disk.

Example:
Deleting notes.txt:

  • File entry removed from directory
  • Storage space becomes free

8. Truncate

Deletes all content but keeps the file.

Example:
notes.txt contains 500 words.
After truncate:

  • File still exists
  • Content becomes empty (0 bytes)

9. Append

Adds new data at the end of the file.

Example:
notes.txt has:

Hello

You append:

World

Final file:

Hello
World

10. Copy

Creates a duplicate file.

Example:
Copy notes.txtcopy_notes.txt

  • Both files now exist with same content

11. Rename

Changes the file name without changing content.

Example:
notes.txtmy_notes.txt

  • Content stays same, only name changes

18. Types of Files

Different types of files are identified by their extensions. Each file type has a specific function.

1. Executable Files

  • Extensions: .exe, .bin, .com
  • Function: Ready-to-run machine language programs.

Example:
Double-clicking chrome.exe starts Google Chrome.

2. Object Files

  • Extensions: .obj, .o
  • Function: Compiled machine code, but not yet linked into an executable program.

Example:
After compiling program.c, the compiler creates program.o.

3. Source Code Files

  • Extensions: .c, .cpp, .java
  • Function: Files containing program source code written by programmers.

Example:
hello.cpp contains C++ code written by the user.

4. Text Files

  • Extensions: .txt, .doc
  • Function: Simple text documents or notes.

Example:
notes.txt contains written notes in Notepad.

5. Library Files

  • Extensions: .lib, .dll
  • Function: Contain reusable functions used by programs.

Example:
A .dll file may provide printing or graphics functions to software.

6. Print/View Files

  • Extensions: .pdf, .zip, .rar
  • Function: Files used for viewing, printing, or sharing compressed information.

Example:
report.pdf is used for reading and printing documents.

7. Archive Files

  • Extensions: .arc, .zip, .tar
  • Function: Group multiple files into one file, often compressed for storage or transfer.

Example:
project.zip contains multiple project files in one package.

8. Multimedia Files

  • Extensions: .mpeg, .mp3, .mp4, .mov
  • Function: Store audio, video, or both (audio-visual) data.

Example:
song.mp3 contains audio music
movie.mp4 contains video and audio

Quick Revision Table

File Type Extensions Function
Executable .exe, .bin, .com Run programs
Object .obj, .o Compiled code (not linked)
Source Code .c, .cpp, .java Program code
Text .txt, .doc Documents
Library .lib, .dll Reusable code
Print/View .pdf, .zip, .rar View/print files
Archive .zip, .tar, .arc Group files
Multimedia .mp3, .mp4, .mpeg Audio/video

 

19. Directories

A directory is used to organize and manage files in a computer system.

Key Points:

  • A directory is a collection of files.
  • It may also contain subdirectories.
  • It stores file information such as:
    • Name
    • Size
    • Location
    • Access permissions
    • Date and time

Types of Directory Structures

There are four main types:

  1. Single-Level Directory
  2. Two-Level Directory
  3. Tree-Structured Directory
  4. Acyclic-Graph Directory

1. Single-Level Directory

Concept:

Only one directory (root directory) exists for all users. All files are stored in the same place.

Structure Diagram:

Root Directory
β”œβ”€β”€ file1.txt
β”œβ”€β”€ file2.cpp
β”œβ”€β”€ file3.doc
β”œβ”€β”€ file4.mp3

Advantages:

  • Very simple to implement
  • Easy to access files

Disadvantages:

  • File naming conflict (same name cannot be used twice)
  • No grouping of files (all files mixed together)
  • Difficult to manage when number of files increases

2. Two-Level Directory

Concept:

Each user has their own separate directory under a root directory.

Structure Diagram:

Root Directory
β”œβ”€β”€ User1
β”‚ β”œβ”€β”€ fileA.txt
β”‚ β”œβ”€β”€ fileB.cpp
β”‚
β”œβ”€β”€ User2
β”‚ β”œβ”€β”€ fileA.txt
β”‚ β”œβ”€β”€ fileC.doc
β”‚
β”œβ”€β”€ User3
β”œβ”€β”€ fileX.mp3

Advantages:

  • Same file names allowed for different users
  • Better file organization
  • Faster search within user directory

Disadvantages:

  • No proper grouping within a user directory
  • Limited sharing of files between users

3. Tree-Structured Directory

Concept:

A hierarchical structure where directories can contain subdirectories and files.

Structure Diagram:

Root
β”œβ”€β”€ UserA
β”‚ β”œβ”€β”€ C_Files
β”‚ β”‚ β”œβ”€β”€ file1.c
β”‚ β”‚ β”œβ”€β”€ file2.c
β”‚ β”œβ”€β”€ Java_Files
β”‚ β”œβ”€β”€ file1.java
β”‚
β”œβ”€β”€ UserB
β”œβ”€β”€ Docs
β”œβ”€β”€ fileA.doc

Advantages:

  • Very well organized structure
  • Easy file grouping
  • Efficient searching using path

Example Path:

To access a file:

Root/UserA/C_Files/file1.c

Disadvantages:

  • File sharing between different branches is difficult

4. Acyclic Graph Directory

Concept:

An extension of tree structure where files or directories can be shared between multiple directories, but cycles are not allowed.

Structure Diagram:

        Root
/ \
UserA UserB
\ /
Shared_File

Explanation:

  • Same file can be shared between multiple users
  • No loops (acyclic structure)

Advantages:

  • Efficient file sharing
  • Saves storage space (no duplicate files)
  • Flexible structure

Disadvantages:

  • More complex to manage
  • Requires link/reference handling
  • Deletion becomes difficult (shared files issue)

20. Access Methods in File System

When a file is stored, its data can be accessed in different ways.
There are three main access methods:

  1. Sequential Access
  2. Direct (Random) Access
  3. Indexed Sequential Access

1. Sequential Access

In sequential access, data is read or written in a fixed order, one record after another.

To reach a record, you must pass through all previous records.

Example:

Magnetic Tape is the best example.

If you want record 50:

  • You must read record 1 → 2 → 3 → ... → 50

Diagram:

Start → R1 → R2 → R3 → R4 → ... → R100 → End
↑ Current Position

Operations:

  • Read next → reads next record
  • Write next → writes next record
  • Rewind → goes back to beginning

Advantages:

  • Simple and easy to implement

Disadvantages:

  • Very slow for searching specific data

2. Direct (Random) Access

In direct access, a file is made up of fixed-size records, and any record can be accessed directly without reading previous records.

Example:

Hard disk, SSD, CD

You can directly jump to record 10 without reading 1–9.

Diagram:

R1   R2   R3   R4   R5   R6   R7   R8

Jump directly to R4
 

Operations:

  • Read n → read record number n
  • Write n → write record number n
  • Jump to n → move directly to record n

Advantages:

  • Very fast access
  • No need to read all previous data

Disadvantages:

  • More complex than sequential access
  • Requires fixed-size records

3. Indexed Sequential Access

This method is a combination of sequential + direct access using an index table.

The index stores:

  • Key value
  • Address (pointer) of record

How it works:

  1. First search in the index
  2. Find pointer
  3. Go directly to the record

Diagram:

INDEX FILE              DATA FILE
--------- ------------
A → 100 A data
B → 200 B data
C → 300 C data
D → 400 D data
Z data

If you search “Z”:

  • First find Z in index
  • Then jump directly to its location

Advantages:

  • Faster than sequential access
  • Easier searching using index
  • Combines speed + order

Disadvantages:

  • Extra memory needed for index
  • Index maintenance is required

 Revision Table

Access Method Meaning Example Speed
Sequential One by one access Magnetic tape Slow
Direct (Random) Jump to any record Hard disk Fast
Indexed Sequential Uses index + direct access Database systems Faster

 

Page 4 of 4