Operating Systems & Administration

[Day 2] 4. Executable File

D
DITISS Admin
••4 min read

!4. Executable File.png

Executable File Structure

An executable file contains several key sections, each serving a specific purpose:

  1. Executable Header:

    • Contains information about the program, such as its name and size.
    • Specifies the type of program (e.g., CLI, GUI, library).
    • Provides the address of the entry point function.
    • Includes information about the remaining sections (start/end).
    • Contains a magic number:
      • Serves as an identifier for the file format.
      • Takes up 2 to 4 bytes of space.
    • Examples:
      • .out
        (Linux): Executable and Linkable Format (ELF)
      • .exe
        (Windows): Portable Executable (MZ)
  2. TEXT Section:

    • Contains instructions in machine code format.
    • Also referred to as the code section.
  3. Data Section:

    • Contains initialised static and global variables.
    • Example:
      int num = 10;
  4. BSS (Block Started by Symbol) Section:

    • Contains uninitialised static and global variables.
    • Example:
      int num;
  5. RO (Read Only) Data Section:

    • Contains read-only data, such as string constants.
    • Example:
      char* ptr = "sunbeam";
  6. Symbol Table:

    • Stores information about symbols.
    • Two types of symbols:
      1. Variables: Includes name, size, address, section, type, etc.
      2. Functions: Includes name, address, return type, and the number and type of arguments.

Process Execution

  • The CPU cannot directly access the hard disk; it requires data to be loaded into RAM for faster access.
  • The loader is responsible for transferring data from the hard disk to RAM while utilising information from the executable header and symbol table.

Memory Structure

  • Stack:

    • Stores the Function Activation Record (FAR) and local variables.
  • Heap:

    • Stores dynamically allocated space.
  • Process Control Block (PCB):

    • Contains information required to control the execution of a process.
    • Stores Process ID (PID) and Parent Process ID (PPID).

Process from OS Perspective

From the operating system's perspective, a process consists of all its sections loaded into memory along with the PCB.

  • The space where the OS is loaded is known as Kernel Space.
  • The space where user applications run is referred to as User Space.

Commands for Process Management

  • Whenever a command is executed, it is treated as a program that is first loaded into RAM, with a PCB created for it.
  1. Top Command:

    • Displays active processes in a top-ordered list.
  2. Echo Command:

    • echo $SHELL
      : Displays the current shell being used.
  3. Process Status Commands:

    • ps
      : Displays the running processes of the current shell.
    • ps -e
      : Displays all running processes in RAM.
    • ps -e -o pid,ppid,cmd
      : Changes the format of the output to show specific details (PID, PPID, command).
  4. TTY:

    • Stands for Terminal.

Read Next

8/26/2026

[Day 2] 5. Process Life Cycle

!5. Process Life Cycle.png The **5-state process model** is commonly used in operating systems to describe the various states a process can be in d...

8/26/2026

[Day 2] 6. Some more commands

### File Manipulation Commands #### Displaying File Content 1. **Number Lines**: `cat -n <filename>` - Displays the contents of the fi...