- LPU MCA Semester 1
- CAP366
- Unit 2
CAP366 · Unit 2: Process
Process concept
10 practice questions · in the MTE and ETE syllabus
Key points
- Process = program in execution (active)
- Program = passive file on disk
- Text, data, heap, stack regions
- Locals on stack, malloc on heap, globals and statics in data
A process is a program in execution: an active entity with a program counter, registers and resources. A program is a passive file on disk. Running the same program twice gives two processes.
The memory image of a process has four regions:
| Region | Holds |
|---|---|
| Text | Executable code |
| Data | Global and static variables |
| Heap | Dynamically allocated memory (malloc), grows upward |
| Stack | Function parameters, return addresses, local variables |
Example: in int g = 5; void f() { int x; static int s; int *p = malloc(4); } the variables g and s are in the data section, x and the pointer p are on the stack, and the block that p points to is on the heap.
Exam pitfall: a pointer variable is stored where it is declared (local means stack); only the object it points to is on the heap. Also, a program is not a process until it is loaded and executing.
Try two questions
Which statement about the stack section of a process is correct?
- It holds memory obtained dynamically through calls such as malloc
- It holds global variables that are initialised before the program starts
- It holds the machine instructions that the CPU executes
- It holds function parameters, return addresses and local variables
Show the answer
D. The stack grows and shrinks as functions are called and return. Each call pushes a frame with parameters, return address and locals.
Why not A: Dynamically allocated memory comes from the heap, not the stack.
Why not B: Initialised globals live in the data section.
Why not C: Instructions are kept in the text (code) section.
Two processes run the same program file. Which part of their images can stay shared in memory for their whole lifetimes?
- The stack, because both begin at main()
- The text section, because its contents are fixed
- The heap, because both call the same malloc routine
- The data section, because both start with identical values
Show the answer
B. Code never changes, so one copy of the text section can serve both processes. Data, heap and stack are written and must be private.
Why not A: Each process has its own call history, so stacks must differ.
Why not C: The heap holds each process's own dynamic data, so it cannot be shared.
Why not D: Writes to globals would otherwise disturb the other process, so data is private.