File Management in UNIX
- Get link
- X
- Other Apps
UNIX is one of the most influential operating systems ever developed, forming the backbone of Linux, macOS, cloud servers, and enterprise systems. One of its greatest strengths is its simple, elegant, and powerful file system structure. This rewritten post explains file management, inodes, directories, system calls, links, IPC, processes, and memory management in UNIX, in a clear and modern style suitable for students, job seekers, and professionals.
SECTION I – FILE MANAGEMENT IN UNIX
1. How UNIX Represents Devices
In UNIX, everything is treated as a file. This includes keyboards, disks, terminals and other hardware components.
All device files are stored inside the /dev directory and are classified as:
✔ Regular File
A normal file that stores user data.
✔ Block Special File
Represents block-oriented devices (like disks). Data transfers occur in blocks.
✔ Character Special File
Represents character-based devices such as keyboards or serial ports, transferring data as a stream.
The beauty of UNIX is that hardware and data files are accessed using the same file-related system calls.
2. What Is an Inode?
An inode is the fundamental data structure that stores metadata about a UNIX file.
An inode contains:
-
File owner ID
-
File type
-
Access permissions
-
Access, modification, and creation times
-
File size
-
Number of links pointing to the file
-
Physical location (addresses of actual data blocks)
Large files use indirect, double-indirect, and triple-indirect pointers to reference more data blocks.
3. Directory Representation in UNIX
A directory in UNIX is also a file.
It contains a list of filename → inode number pairs.
Each directory automatically contains:
-
.(refers to itself) -
..(refers to parent directory)
Directories can be created using:
mkdir(pathname, mode)
Only the kernel modifies directories; user programs can only read them.
4. UNIX System Calls for File I/O
Some commonly used calls:
| System Call | Description |
|---|---|
open() | Opens a file |
creat() | Creates a file |
read() | Reads from file |
write() | Writes to file |
close() | Closes file |
lseek() | Moves read/write pointer |
dup(), dup2() | Duplicates file descriptors |
fcntl() | Changes properties of open files |
ioctl() | Device-specific operations |
5. Changing File Permissions
UNIX file permissions are divided into:
user | group | others
r w x | r w x | r w x
Using numeric representation:
-
r = 4 -
w = 2 -
x = 1
Example:
To give permissions rw-rw-r--:
chmod(filename, 0664)
6. Links vs Symbolic Links
✔ Hard Link
-
A second name for an existing file
-
Cannot span across file systems
-
Cannot link directories
✔ Symbolic Link (Soft Link)
-
A file that points to another file by name
-
Can link across file systems
-
Can link directories
Commands:
ln file1 file2
ln -s file1 file2
7. What Is a FIFO?
A FIFO (named pipe) is a special file that provides first-in-first-out communication between processes.
Key features:
-
Data is read only once
-
Writer writes at one end, reader receives at the other
-
Used in IPC
8. Creating Special Files
Using mknod() system call, UNIX can create:
-
Device files
-
Named pipes
-
Special files
9. Mount and Unmount System Calls
UNIX allows a file system to be attached (mounted) to a directory.
mount(source, target)
umount(target)
Example: When you insert a CD, the OS mounts it under /dev/cdrom.
10. Mapping Inode to Data Blocks
Each inode contains 13 block pointers:
-
10 direct pointers
-
1 single-indirect
-
1 double-indirect
-
1 triple-indirect
This structure allows UNIX to support extremely large files.
11. What Is a Shell?
A shell is an interface between the user and the operating system.
Popular shells:
-
sh -
bash -
csh -
ksh
The shell converts user commands into system calls.
SECTION II – PROCESS MODEL & IPC
1. How UNIX Boots (Initial Process Sequence)
When UNIX boots:
-
Kernel creates swapper (PID 0)
-
Swapper creates:
-
Process dispatcher (PID 1)
-
vhand (PID 2)
-
dbflush (PID 3)
-
PID 1 ultimately launches the shell.
2. Process Identifiers
Each process has:
-
PID – Process ID
-
PPID – Parent Process ID
-
UID – User ID
-
EUID – Effective User ID
3. fork() System Call
fork() creates a child process.
-
Parent receives child PID
-
Child receives
0
4. Example – Output Prediction
fork();
printf("Hello World!");
Output:
Hello World!Hello World!
Because both parent and child execute printf.
Multiple fork() calls multiply processes:
n forks → 2^n processes.
5. Important Process-Related System Calls
| System Call | Purpose |
|---|---|
| fork() | Creates new process |
| exec() | Replaces process memory |
| wait() | Waits for child to finish |
| exit() | Terminates process |
| getpid() | Returns PID |
| nice() | Adjusts process priority |
6. Zombie Process
A process that has finished execution but remains in the process table because the parent has not read its exit status.
Appears as Z in ps.
7. Daemons
Background processes detached from terminals.
Examples:
-
init -
cron -
inetd
8. Interprocess Communication (IPC)
✔ Pipes
Parent ↔ Child communication
✔ Message Queues
Unrelated processes can communicate.
✔ Shared Memory
Fastest IPC but requires synchronization (mutex, semaphores).
SECTION III – MEMORY MANAGEMENT
1. Swapping vs Paging
✔ Swapping
Entire process is moved between disk ↔ memory.
✔ Paging
Only required memory pages are moved.
Enables virtual memory.
2. Memory Management Goals
-
Decide which processes stay in memory
-
Manage virtual address spaces
-
Maintain swap device space
-
Track free memory
3. What Is a Region?
A region is a continuous part of a process address space (text, data, stack).
Shared between processes when possible.
4. Working Set & Locality Principle
Programs tend to reuse a small set of pages frequently (locality of reference).
Working set = pages referenced recently.
5. Page Fault
Occurs when a process tries to access a page that is not in RAM.
Two types:
-
Validity fault
-
Protection fault
6. Page Stealer Process
A kernel process responsible for freeing memory by swapping out pages not actively used.
7. fork() vs vfork()
✔ fork()
Makes a full copy of parent memory.
✔ vfork()
Child shares parent memory until exec(), making it faster but risky.
FINAL SUMMARY
This rewritten post explains the entire UNIX file, process, and memory management system in a clean, modern, readable format. Each concept—from inodes to daemons, from paging to IPC—is explained to help students, interviewees, and professionals understand UNIX deeply
Comments
THANK YOU FOR THE INFORMATION
ReplyDeletePLEASE VISIT US
customized erp software