Linux Process Management and File System Architecture

Starting Processes in Linux

Processes can be started in two ways:

Foreground Processes

A foreground process runs normally on the terminal and occupies the shell until it finishes. The user cannot run another command until this process completes.

Example: $ ls or $ firefox

To start a process in the foreground, simply use the command_name.

Background Processes

A background process runs behind the terminal, allowing the user to continue working. A background process command ends with &.

Example: $ firefox & or $ gedit &

To see all background jobs, use: $ jobs

Using nohup

The nohup command is used to run a process even after logging out.

Example: $ nohup script.sh &

Stopping Processes in Linux

Linux provides many ways to stop or terminate a process.

Stop Foreground Processes

You can stop a currently running foreground process using:

  • Ctrl + C → Kills the process immediately (SIGINT).
  • Ctrl + Z → Stops/pauses the process and sends it to the background (SIGSTOP).

Killing a Process by PID

  1. First, find the process ID: $ ps or $ ps -e
  2. Kill the process using the kill command: $ kill PID
  3. To forcefully kill a process: $ kill -9 PID

Killing by Process Name

If you do not know the PID, use: $ killall process_name

Example: $ killall firefox

Stopping Background Processes

To bring a background process to the foreground, use:

$ fg %job_number

Then stop it using Ctrl + C or the kill command.

Job Control and Scheduling

Job control in Linux allows users to schedule commands or programs to run automatically at a specific time or in the background without manual input. Linux provides several job-scheduling utilities such as at, batch, cron, and time for handling one-time, repetitive, or delayed tasks.

at Command (One-Time Scheduling)

  • The at command is used to schedule a job once at a specific time in the future.
  • It is helpful for tasks like shutting down the system at midnight or sending a reminder.
  • To use it: $ at 10:30 PM
  • Input the command: at> shutdown -h now
  • Press Ctrl + D to save.
  • To see scheduled jobs: $ atq
  • To remove a scheduled job: $ atrm job_number

batch Command (Low-load Scheduling)

  • The batch command executes jobs when the system load is low.
  • It is useful for heavy tasks to avoid slowing down the system.
  • Batch queues jobs automatically when CPU usage is free: $ batch
  • Input the command: at> ./backup.sh
  • Press Ctrl + D to save.

cron Command (Repeated / Periodic Jobs)

  • cron is used to schedule repeated tasks (hourly, daily, weekly, monthly).
  • It works using a table called crontab.
  • Open the cron file: $ crontab -e
  • Cron format: minute hour day month weekday command
  • Example: Run backup daily at 7 AM: 0 7 * * * /home/user/backup.sh
  • List cron jobs: $ crontab -l

time Command (Execution Time Measurement)

  • The time command is not a scheduler.
  • It is used to measure how long a process takes to execute.
  • It shows: real time, user CPU time, and system CPU time.
  • Example: $ time ls

Importance of Job Control

  • Automates routine tasks.
  • Saves time and effort.
  • Ensures tasks run even when the user is offline.

Linux File System Components

A file system in Linux is the method used to store, organize, and manage files on a disk. Linux follows a hierarchical directory structure starting from the root (/). The file system contains different components that help the operating system handle files, directories, permissions, and storage.

1. Superblock

The superblock is one of the most important components of the Linux file system. It contains essential information about the file system such as:

  • Size of the file system
  • Number of blocks
  • Free and used blocks
  • Location of the inode table

If the superblock is corrupted, the file system may not mount.

2. Inodes

  • Every file and directory has a unique inode (index node).
  • Inodes store metadata about files such as:
    • File size
    • Owner and permissions
    • Timestamps
    • Disk block addresses
  • It does not store the file name.

3. Data Blocks

  • These are the actual storage locations on the disk where file data is stored.
  • When a file is created, Linux allocates data blocks to store its contents.
  • Large files use multiple data blocks.

4. Directory Structure

  • A directory is also a file containing entries that map file names to inode numbers.
  • Linux uses a hierarchical structure starting with root (/).
  • Examples of major directories:
    • /bin – Essential commands
    • /etc – Configuration files
    • /home – User home directories
    • /var – Variable data

5. File Name and Path

The file name is stored in the directory entry, not inside the inode. A path (absolute or relative) helps locate a file in the directory tree.

Example: /home/user/document.txt

6. Mount Points

  • Linux allows attaching a file system to a directory using mount.
  • Example: mount /dev/sda1 /mnt
  • Mount points help access different partitions and devices.

Mechanism of Process Creation

Process creation in Linux is mainly handled by two important system calls: fork() and exec(). Every process in Linux is created from an already running process. The kernel uses this mechanism to maintain process hierarchy and efficiently manage system resources.

1. Parent and Child Process Concept

  • When a process creates another process, it becomes the parent process.
  • The newly created process is called the child process.
  • The parent and child have separate PIDs but share some resources initially.

2. Steps in Process Creation Mechanism

  • (a) fork() – Creating a copy: The fork() system call is used to create a new process. It creates a duplicate of the parent process. The child gets a different PID but the same code and memory structure initially.
  • (b) exec() – Replacing the process image: After a child process is created, it often uses exec() to load a new program. This replaces the child’s previous program with a new one. Thus, fork creates the process and exec loads the program.
  • (c) Copy-on-Write (COW) Optimization: Linux uses the Copy-on-Write technique for performance. Instead of copying the whole memory at fork time, the parent and child share memory. Memory is copied only when either process tries to modify it.

3. Process Creation Tree

  • Linux maintains a hierarchical tree of processes.
  • Every process has a parent except the first one (init or systemd).
  • Commands like ps and pstree show this hierarchy.
  • Example: systemd (PID 1) → bash → firefox

4. Environment Setup

When a new process is created, it inherits the parent’s environment variables, file descriptors, working directory, and user permissions. This ensures the child process starts in a valid environment.

Standard Linux File System Hierarchy

The standard file system in Linux refers to the organized and hierarchical structure used to store files, directories, and system resources. Linux follows the FHS (File System Hierarchy Standard), which defines how directories and files should be arranged. This makes Linux systems uniform, predictable, and easy to manage. The Linux file system starts from the root directory /, and every file or directory exists under it.

1. Root Directory /

  • The top-most directory of the file system.
  • All other directories are branches of the root.
  • Contains essential system folders.

2. Important Standard Directories

  • /bin: Contains essential command binaries like ls, cp, mv, and cat. Used by all users.
  • /sbin: Contains system binaries used by administrators, such as ifconfig, fdisk, and reboot.
  • /etc: Stores system configuration files like fstab, passwd, and hosts.
  • /home: Stores personal directories of users (e.g., /home/rohit).
  • /root: The home directory of the root (admin) user, separate from normal user directories.
  • /usr: Stands for “Unix System Resources.” Contains user-level programs, libraries, and documentation (e.g., /usr/bin, /usr/lib).

3. Hierarchical Structure

  • Files are arranged like a tree, starting from /.
  • This makes navigation easy and avoids confusion.
  • Example path: /home/user/Documents/file.txt

4. Importance of the Standard File System

  • Makes system administration easy.
  • Ensures consistency across Linux distributions.
  • Helps in backups, troubleshooting, and security.

Linux File System Types

A file system type defines how data is stored, organized, and managed on a storage device. Linux supports many types of file systems, each designed for different performance, security, and reliability needs.

  • ext2 (Second Extended File System): One of the oldest Linux file systems. It does not support journaling. Used earlier for small storage devices and older systems. Fast performance but not safe during sudden shutdowns.
  • ext3 (Third Extended File System): An improved version of ext2 with journaling. Journaling helps recover data quickly after crashes. It is backward compatible with ext2 and suitable for servers and desktops.
  • ext4 (Fourth Extended File System): Features faster read/write operations. It is the default file system for many modern Linux distributions. Supports large files (up to 16 TB) and huge volumes. More reliable due to advanced journaling.
  • XFS: A high-performance journaling file system developed by SGI. Excellent for large files, databases, and enterprise servers. Supports parallel I/O for better speed.
  • Btrfs (B-tree File System): A modern Linux file system with advanced features like snapshots, RAID support, and auto-repair. Useful for cloud systems and large storage servers; known as a “next-generation” file system.
  • FAT32 and exFAT: FAT32 has a file size limit of 4 GB. Supported mainly for compatibility with Windows and external devices. exFAT removes this limitation and is commonly used in USB drives and SD cards.
  • NTFS: The Windows default file system. Linux supports reading and writing through drivers. Used for data sharing between Linux and Windows.