Process and Process Creation – A Simple Overview

1. What Is a Process?

A process is one of the most fundamental abstractions provided by an operating system.

👉 Informal definition:
A process is a running program.

  • A program by itself is passive—it is just a set of instructions and data stored on disk.

  • A process is active—it is what the program becomes when the operating system loads it into memory and starts executing it.

For example:

  • A web browser stored on disk is a program

  • When you double-click it and it starts running, it becomes a process

Modern systems usually run many processes at the same time, such as:

  • Web browsers

  • Music players

  • Email clients

  • Games


2. The Illusion of Many CPUs: CPU Virtualization

Even if a system has only one CPU (or a few CPUs), it appears as if many programs run simultaneously.

Key Question (The Crux of the Problem)

How does the OS provide the illusion of many CPUs when only a few exist?

Answer: Time Sharing

The OS virtualizes the CPU using time sharing:

  • Run one process for a short time

  • Stop it

  • Run another process

  • Repeat very quickly

Because this switching happens fast, users perceive that all programs run in parallel.

⚠️ Trade-off:
More processes → each process gets less CPU time → performance may decrease.


3. Mechanisms and Policies in Process Management

Operating systems use two important concepts:

1. Mechanisms (How things are done)

Low-level operations that make functionality possible.

  • Example: Context switch

    • Stops one process

    • Saves its state

    • Restores another process’s state

2. Policies (Which decision to make)

High-level rules that decide what to do.

  • Example: CPU scheduling policy

    • Which process should run next?

    • Based on priority, fairness, responsiveness, etc.

💡 Design Principle:
Separating policy from mechanism improves modularity and flexibility.


4. What Makes Up a Process? (Process State)

A process is defined by its machine state, which includes:

1. Address Space (Memory)

  • Instructions (code)

  • Static data

  • Heap (dynamic memory)

  • Stack (function calls, local variables)

2. CPU Registers

  • General registers

  • Program Counter (PC): points to the next instruction

  • Stack Pointer: manages function calls

3. I/O Information

  • List of open files

  • Input/output resources

Together, these elements fully describe the current execution of a process.


5. Process API: What Can the OS Do With Processes?

Every modern OS provides basic process operations:

  1. Create

    • Start a new process (e.g., running a command)

  2. Destroy

    • Forcefully terminate a process

  3. Wait

    • Pause until a process finishes

  4. Control

    • Suspend and resume processes

  5. Status

    • Query information (state, execution time, etc.)


6. How Is a Process Created?

Process creation transforms a program on disk into a running process.

Step 1: Load Program into Memory

  • OS reads the executable from disk

  • Loads:

    • Code

    • Static (initialized) data

  • Modern OSes use lazy loading:

    • Load parts only when needed


Step 2: Set Up the Stack

  • OS allocates memory for the stack

  • Used for:

    • Function calls

    • Local variables

    • Return addresses

  • Initializes parameters for main() (argc, argv)


Step 3: Set Up the Heap

  • Heap is used for dynamic memory allocation (malloc, free)

  • Initially small

  • Grows as the program requests more memory


Step 4: Initialize I/O

  • OS opens default file descriptors:

    • Standard input

    • Standard output

    • Standard error

  • Enables interaction with keyboard and screen


Step 5: Start Execution

  • OS transfers control to the program’s entry point (main())

  • The process begins executing

  • CPU is now running the process






7. Program vs Process (Key Difference)

Program            Process
Stored on disk            Loaded into memory
Passive            Active
Static            Dynamic
No execution state            Has registers, memory, I/O state

8. Summary

  • A process is a running program managed by the OS.

  • The OS creates the illusion of multiple CPUs using time sharing.

  • A process consists of memory, registers, and I/O state.

  • Process creation involves:

    1. Loading code and data

    2. Initializing stack and heap

    3. Setting up I/O

    4. Starting execution at main()

Understanding processes is essential for learning:

  • CPU scheduling

  • Context switching

  • Multitasking

  • Performance optimization


Comments

Popular posts from this blog

Operating Systems OS PCCST403 Semester 4 BTech KTU CS 2024 Scheme

Introduction to Operating System -Virtualization, Concurrency, and Persistence

Operating Systems PCCST403 Scheme and Syllabus