1. LPU MCA Semester 1
  2. CAP366
  3. 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:

RegionHolds
TextExecutable code
DataGlobal and static variables
HeapDynamically allocated memory (malloc), grows upward
StackFunction 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

Question 1 · Tier 2, Understand

Which statement about the stack section of a process is correct?

  1. It holds memory obtained dynamically through calls such as malloc
  2. It holds global variables that are initialised before the program starts
  3. It holds the machine instructions that the CPU executes
  4. 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.

Question 2 · Tier 4, Analyse

Two processes run the same program file. Which part of their images can stay shared in memory for their whole lifetimes?

  1. The stack, because both begin at main()
  2. The text section, because its contents are fixed
  3. The heap, because both call the same malloc routine
  4. 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.