Unit 8 subjective questions Process Management
CSE105 — Creative Engineering Workshop 20 questions with model answers. Write yours first, then compare.
-
Question 1 of 20
Define the term process in the context of an operating system. How does a process differ from a program?
Model answer
A process is an instance of a program that is currently being executed by the operating system. It is an active entity that includes the program code, its current activity (represented by the program counter), and a set of associated resources.
Key differences between a Process and a Program:
- Nature:
- A program is a passive entity — a set of instructions stored on disk (an executable file).
- A process is an active entity — a program in execution loaded into memory.
- Lifetime:
- A program exists permanently until deleted.
- A process exists only during execution and terminates when execution completes.
- Resources:
- A program does not consume system resources while stored.
- A process actively consumes CPU time, memory, registers, and I/O resources.
- Multiplicity:
- A single program can spawn multiple processes (e.g., opening multiple instances of a text editor).
In summary, a program becomes a process when it is loaded into memory and begins execution.
- Nature:
-
Question 2 of 20
Explain the different states of a process with a suitable state transition diagram description.
Model answer
A process passes through several states during its lifetime. The primary process states are:
- New: The process is being created.
- Ready: The process is loaded into main memory and waiting to be assigned to the CPU.
- Running: Instructions of the process are being executed by the CPU.
- Waiting (Blocked): The process is waiting for some event to occur (e.g., I/O completion).
- Terminated: The process has finished execution and is removed from memory.
State Transitions:
- New → Ready: Process admitted to the ready queue.
- Ready → Running: Scheduler dispatches the process to the CPU.
- Running → Ready: Process is preempted (time quantum expires).
- Running → Waiting: Process requests I/O or waits for an event.
- Waiting → Ready: The awaited event completes.
- Running → Terminated: Process completes execution.
This cyclic movement allows efficient CPU utilization through multiprogramming, ensuring the processor is never idle when work is available.
-
Question 3 of 20
What is a Process ID (PID)? Describe its significance and how it is assigned in Unix/Linux systems.
Model answer
A Process ID (PID) is a unique numerical identifier assigned by the operating system kernel to every process running on the system.
Significance of PID:
- Unique Identification: Each active process is uniquely identified by its PID, allowing the kernel and users to reference it.
- Process Control: Commands like
kill,renice, andwaituse the PID to target specific processes. - Process Tracking: Utilities like
psandtopdisplay PIDs for monitoring.
How PIDs are assigned:
- PIDs are assigned sequentially by the kernel as processes are created.
- PID 1 is always assigned to the
init(orsystemd) process, the first process started at boot. - PID 0 typically refers to the scheduler/swapper kernel process.
- When PIDs reach the system maximum, the counter wraps around and reuses freed (dead) PIDs.
- A child process can obtain its Parent Process ID using the PPID.
In shell scripting, the special variable
$$returns the PID of the current shell, and$!returns the PID of the last background process. -
Question 4 of 20
Describe the
pscommand in Linux. Explain its commonly used options with examples.Model answer
The
ps(process status) command displays information about currently running processes as a snapshot at the moment the command is executed.Basic syntax:
Bashps [options]Commonly used options:
ps— Shows processes for the current shell only.ps -eorps -A— Displays all processes running on the system.ps -f— Full-format listing (shows UID, PID, PPID, C, STIME, TTY, TIME, CMD).ps -ef— Combines all processes with full-format details (very common).ps aux— BSD-style output showing user, %CPU, %MEM, VSZ, RSS, and command.ps -u username— Lists processes owned by a specific user.ps -p PID— Displays information for a specific PID.
Example:
Bashps -ef | grep firefoxThis lists all processes and filters those related to firefox.
Key columns explained:
- PID: Process ID
- PPID: Parent Process ID
- TTY: Terminal associated with the process
- TIME: Cumulative CPU time used
- CMD: Command that started the process
-
Question 5 of 20
Explain the
topcommand. How does it help in real-time process monitoring? Describe key fields in its output.Model answer
The
topcommand provides a dynamic, real-time view of the running system, continuously updating information about processes and overall resource usage.How it helps:
- Displays live CPU and memory usage.
- Identifies resource-hungry processes.
- Allows interactive process management (killing, renicing) directly from the interface.
Summary (Header) fields:
- uptime: How long the system has been running.
- load average: System load over 1, 5, and 15 minutes.
- Tasks: Total, running, sleeping, stopped, and zombie processes.
- %Cpu(s): Breakdown of CPU usage (us=user, sy=system, id=idle, wa=I/O wait).
- Mem / Swap: Total, used, and free memory.
Per-process columns:
- PID: Process ID
- USER: Owner of the process
- PR / NI: Priority and Nice value
- %CPU: CPU usage percentage
- %MEM: Memory usage percentage
- TIME+: Total CPU time used
- COMMAND: Command name
Interactive keys inside top:
k— Kill a process (prompts for PID).r— Renice a process.M— Sort by memory usage.P— Sort by CPU usage.q— Quit.
-
-
Question 6 of 20
Distinguish between the
psandtopcommands.Model answer
Both
psandtopare used to monitor processes, but they differ significantly in behavior and usage.Feature pstopNature of output Static snapshot at execution time Dynamic, real-time continuously updating display Update Runs once and exits Refreshes automatically (default every 3 sec) Interactivity Non-interactive Interactive (kill, renice, sort) Resource summary No overall system summary Shows CPU, memory, load average, uptime Scripting Easily used in scripts and pipes Not ideal for scripting Output control Highly customizable columns Fixed but sortable columns Summary:
- Use
pswhen you need a one-time snapshot or want to pipe output into scripts (e.g.,ps -ef | grep). - Use
topwhen you need continuous, live monitoring of system performance and interactive control over processes.
- Use
-
Question 7 of 20
What are jobs in the context of shell process management? Explain the
jobscommand with an example.Model answer
In shell terminology, a job is a process (or a group of processes/pipeline) started from and managed by a particular shell session. Jobs can run in the foreground or background.
The
jobscommand:The
jobscommand lists all jobs that are running or stopped in the current shell session, along with their job numbers and states.Syntax:
Bashjobs [options]Common options:
jobs -l— Shows job numbers along with their PIDs.jobs -r— Shows only running jobs.jobs -s— Shows only stopped jobs.
Example:
Bash$ sleep 300 & [1] 4521 $ sleep 500 & [2] 4522 $ jobs [1]- Running sleep 300 & [2]+ Running sleep 500 &Interpreting the output:
[1],[2]— Job numbers used withfg,bg, andkill.+— Indicates the current (default) job.-— Indicates the previous job.- State — Running or Stopped.
-
Question 8 of 20
Explain foreground and background processes. Describe the
fgandbgcommands with examples.Model answer
Foreground process:
- A process that runs in the terminal and occupies it, preventing other commands from being entered until it completes.
- It receives keyboard input directly.
Background process:
- A process that runs behind the scenes, freeing the terminal for other commands.
- Started by appending an ampersand
&to the command.
The
bgcommand:Resumes a stopped job and runs it in the background.
Bash$ sleep 300 # running in foreground ^Z # press Ctrl+Z to suspend it [1]+ Stopped sleep 300 $ bg %1 # resume job 1 in background [1]+ sleep 300 &The
fgcommand:Brings a background or stopped job into the foreground.
Bash$ fg %1 # bring job 1 to foreground sleep 300Key points:
Ctrl+Zsuspends the current foreground job.&starts a command directly in the background.%nrefers to job number n infgandbg.
-
Question 9 of 20
Describe the
killcommand in detail. Explain how signals are used to control processes.Model answer
The
killcommand is used to send signals to processes, most commonly to terminate them. Despite its name,killcan send any signal, not just termination signals.Syntax:
Bashkill [signal] PIDCommon signals:
SIGTERM (15)— Default signal; requests graceful termination, allowing cleanup.SIGKILL (9)— Forcefully terminates a process immediately; cannot be caught or ignored.SIGHUP (1)— Hangup; often used to reload configuration.SIGINT (2)— Interrupt (equivalent to Ctrl+C).SIGSTOP (19)— Suspends the process.SIGCONT (18)— Resumes a stopped process.
Examples:
Bashkill 4521 # sends default SIGTERM to PID 4521 kill -9 4521 # forcefully kills PID 4521 kill -SIGKILL 4521 # same as above using signal name kill -l # lists all available signalsBest practice:
- Always try
SIGTERM (15)first to allow graceful shutdown. - Use
SIGKILL (9)only when a process is unresponsive, as it does not allow cleanup and may cause data loss.
-
Question 10 of 20
Explain the
pkillcommand. How does it differ from thekillcommand?Model answer
The
pkillcommand sends signals to processes based on their name and other attributes rather than their PID.Syntax:
Bashpkill [options] patternExamples:
Bashpkill firefox # kills all processes named firefox pkill -9 chrome # forcefully kills all chrome processes pkill -u john # kills all processes owned by user john pkill -f "python app.py" # matches against the full command lineDifference between
killandpkill:Feature killpkillTarget Specific PID(s) Process name / pattern Multiple processes Must list each PID Kills all matching at once Convenience Requires knowing PID Only needs process name Precision Very precise (one process) Can affect many processes unintentionally Caution:
pkillcan accidentally terminate multiple processes matching the pattern, so patterns should be specific.- Use
pgrepfirst to preview which processes will be matched before runningpkill.
-
Question 11 of 20
Distinguish between the
killandpkillcommands, and explain when each should be preferred.Model answer
Both commands send signals to processes but use different targeting mechanisms.
kill:- Targets processes by their PID (Process ID).
- Requires the exact numerical PID.
- Ideal when you know the specific process you want to signal.
pkill:- Targets processes by name, user, or other attributes using pattern matching.
- Can signal multiple processes simultaneously.
- Ideal when you don't know the PID but know the process name.
Comparison Table:
Aspect killpkillSelection criteria PID Name/pattern/attributes Scope Usually a single process Potentially many processes Prerequisite Must find PID (via ps/top)Only process name needed Risk level Low (precise) Higher (broad matching) When to prefer:
- Use
killfor precise control over a single, known process. - Use
pkillfor convenience when terminating all instances of a named application (e.g., all hung browser tabs).
-
Question 12 of 20
Explain the concept of a zombie process and an orphan process. How do they occur and how are they handled?
Model answer
Zombie Process:
- A zombie (defunct) process is one that has completed execution but still has an entry in the process table.
- This occurs because the process's exit status has not yet been read by its parent using
wait(). - Zombies consume no CPU or memory but occupy a PID slot.
- In
psoutput, they appear with stateZand are marked<defunct>. - Handling: The parent must call
wait()to reap the child. If a parent fails to do so, accumulated zombies can be cleared only when the parent is killed (reparenting toinit, which reaps them).
Orphan Process:
- An orphan is a process whose parent has terminated while the child is still running.
- Orphans are automatically adopted by the
init(PID 1) orsystemdprocess. initthen becomes responsible for reaping the orphan when it terminates, preventing it from becoming a permanent zombie.
Key difference:
- A zombie is dead but not reaped; an orphan is alive but has lost its parent.
- Zombies are a resource concern (PID exhaustion in extreme cases), while orphans are handled gracefully by the OS.
-
Question 13 of 20
Describe the significance of the Nice value and priority of a process. How can they be modified in Linux?
Model answer
Priority:
- Every process has a scheduling priority that determines how much CPU time it receives relative to others.
- Lower priority numbers generally mean higher scheduling importance.
Nice Value:
- The nice value (NI) is a user-space mechanism to influence a process's priority.
- It ranges from -20 (highest priority) to +19 (lowest priority).
- A higher nice value means the process is "nicer" to others, yielding CPU time.
- Default nice value is 0.
Modifying nice values:
nice— Start a process with a specified nice value:
Bashnice -n 10 ./myscript.shrenice— Change the nice value of a running process:
Bashrenice -n 5 -p 4521Important points:
- Only the superuser (root) can assign negative nice values (raising priority).
- Normal users can only lower priority (increase nice value).
- The nice value is visible in the NI column of
topandps.
This mechanism allows administrators to balance CPU allocation among competing processes.
-
Question 14 of 20
With suitable examples, explain how to start, suspend, resume, and terminate a job using shell job control commands.
Model answer
Shell job control allows a user to manage multiple tasks from a single terminal. Here is a complete workflow:
1. Starting a job in the background:
Bash$ sleep 600 & [1] 7890 The `&` runs the job in the background; `[1]` is the job number and `7890` is the PID.2. Starting a job in the foreground and suspending it:
Bash$ sleep 600 ^Z # Ctrl+Z suspends the job [1]+ Stopped sleep 6003. Resuming a suspended job in the background:
Bash$ bg %1 [1]+ sleep 600 &4. Bringing a background job to the foreground:
Bash$ fg %1 sleep 6005. Listing jobs:
Bash$ jobs -l [1]+ 7890 Running sleep 600 &6. Terminating a job:
Bash$ kill %1 # using job number $ kill 7890 # using PIDSummary of control keys:
&— Run in background.Ctrl+Z— Suspend foreground job.Ctrl+C— Terminate foreground job (SIGINT).bg/fg— Move jobs between background and foreground.
-
Question 15 of 20
Compare foreground and background processes across multiple dimensions, and explain the trade-offs of using each.
Model answer
Understanding when to use foreground versus background execution is essential for efficient shell usage.
Dimension Foreground Process Background Process Terminal control Occupies terminal fully Frees the terminal Input Receives keyboard input Cannot easily receive input Starting method Run command normally Append &to commandUser interaction Interactive tasks Long-running / non-interactive tasks Output Directly to terminal May clutter terminal unless redirected Ctrl+C Terminates it directly Not affected by Ctrl+C of shell Trade-offs:
- Foreground advantages: Easy interaction, immediate feedback, simple to terminate with Ctrl+C.
- Foreground disadvantages: Blocks the terminal until completion.
- Background advantages: Allows multitasking, ideal for long jobs like compilation or downloads.
- Background disadvantages: Output can interfere with terminal; requires redirection (e.g.,
> output.log 2>&1); harder to interact with.
Best practice: Run long, non-interactive tasks in the background with output redirected, while reserving the foreground for interactive commands.
-
Question 16 of 20
Explain the concept of a Process Control Block (PCB). What information does it contain and why is it important?
Model answer
A Process Control Block (PCB) is a data structure maintained by the operating system for every process. It stores all the information needed to manage and control that process.
Information contained in a PCB:
- Process ID (PID): Unique identifier of the process.
- Process State: Current state (new, ready, running, waiting, terminated).
- Program Counter: Address of the next instruction to execute.
- CPU Registers: Contents of all process-related registers.
- CPU Scheduling Information: Priority, scheduling queue pointers, nice value.
- Memory Management Information: Page tables, segment tables, base/limit registers.
- Accounting Information: CPU time used, time limits, process numbers.
- I/O Status Information: List of open files and allocated I/O devices.
Importance of the PCB:
- Context Switching: During a context switch, the state of the running process is saved into its PCB, and the state of the next process is loaded from its PCB.
- Process Management: Enables the OS to track, suspend, resume, and terminate processes accurately.
- Resource Tracking: Keeps records of resources assigned to each process.
The PCB is thus the backbone of process management, making multiprogramming and multitasking possible.
-
Question 17 of 20
Describe the process creation mechanism in Unix/Linux using
fork()andexec()system calls.Model answer
In Unix/Linux, new processes are created through a combination of the
fork()andexec()system calls.The
fork()system call:- Creates a new (child) process that is an almost exact copy of the parent process.
- The child gets a new unique PID, while inheriting the parent's code, data, and open files.
- Return values:
- Returns 0 to the child process.
- Returns the child's PID to the parent process.
- Returns -1 on failure.
The
exec()family of calls:- Replaces the current process image with a new program.
- The PID remains the same, but the code, data, and stack are replaced.
- Common variants:
execl(),execv(),execlp(),execvp().
Typical creation pattern:
- Parent calls
fork()to create a child. - The child calls
exec()to load and run a new program. - The parent may call
wait()to wait for the child to finish and reap it.
Example flow (conceptual):
Cpid = fork(); if (pid == 0) { execvp("ls", args); // child runs 'ls' } else { wait(NULL); // parent waits }This fork-exec model cleanly separates process creation from program loading, giving great flexibility.
-
Question 18 of 20
You notice that a runaway process named
dataprocis consuming 100% CPU. Describe a complete step-by-step procedure to identify and terminate it using process management commands.Model answer
Here is a systematic approach to diagnose and terminate a runaway process:
Step 1 — Identify the offending process:
Use
topto observe real-time CPU usage:Bashtop Press **`P`** to sort by CPU usage; the `dataproc` process will appear near the top with its PID and %CPU.Step 2 — Find the exact PID:
Alternatively, use
pswith filtering:Bashps -ef | grep dataproc or use `pgrep`: bash pgrep -l dataprocStep 3 — Attempt graceful termination:
Send the default SIGTERM (15) to allow cleanup:
Bashkill 8123 # replace with actual PIDStep 4 — Verify termination:
Bashps -p 8123 If no output, the process ended successfully.Step 5 — Force kill if unresponsive:
If the process ignores SIGTERM, use SIGKILL (9):
Bashkill -9 8123 or kill all instances by name: bash pkill -9 dataprocStep 6 — Confirm resource recovery:
Return to
topto confirm CPU usage has normalized.Best practice: Always try graceful termination first; use
kill -9only as a last resort to avoid data corruption. -
Question 19 of 20
Explain the concept of context switching. Describe the steps involved and discuss its overhead.
Model answer
Context Switching is the mechanism by which the CPU switches from executing one process (or thread) to another, enabling multitasking.
Why it is needed:
- Allows multiple processes to share a single CPU.
- Occurs during interrupts, system calls, time-slice expiry, or when a process blocks for I/O.
Steps involved in a context switch:
- Save state: The current process's context (program counter, CPU registers, state) is saved into its PCB.
- Update PCB: The state of the outgoing process is updated (e.g., to Ready or Waiting).
- Select next process: The scheduler selects the next process from the ready queue.
- Load state: The saved context of the selected process is loaded from its PCB into the CPU.
- Resume execution: The CPU resumes the new process from where it left off.
Overhead of context switching:
- Context switching is pure overhead — no useful user work is done during the switch.
- Costs include saving/loading registers, updating memory maps, and flushing CPU caches/TLB.
- Excessive context switching (thrashing) degrades performance.
Reducing overhead:
- Efficient scheduling algorithms.
- Larger time quanta (with trade-offs in responsiveness).
- Hardware support for fast state saving.
Thus context switching is essential for concurrency but must be minimized to maintain efficiency.
-
Question 20 of 20
Discuss the various types of signals in Linux and explain how processes can handle, ignore, or be terminated by them.
Model answer
Signals are software interrupts used by the operating system to notify a process that an event has occurred. They are a fundamental inter-process communication and control mechanism.
Common signals:
SIGHUP (1)— Hangup; terminal closed or reload configuration.SIGINT (2)— Interrupt from keyboard (Ctrl+C).SIGQUIT (3)— Quit from keyboard (Ctrl+\), generates core dump.SIGKILL (9)— Forcefully kills a process; cannot be caught or ignored.SIGTERM (15)— Requests graceful termination (default forkill).SIGSTOP (19)— Suspends a process; cannot be caught or ignored.SIGCONT (18)— Resumes a stopped process.SIGSEGV (11)— Invalid memory reference (segmentation fault).
How processes respond to signals:
- Default action: Each signal has a predefined default (e.g., terminate, ignore, stop).
- Catch/Handle: A process can register a signal handler function to execute custom code when a catchable signal is received.
- Ignore: A process can choose to ignore certain signals (except SIGKILL and SIGSTOP).
- Block: Signals can be temporarily blocked (masked) and delivered later.
Uncatchable signals:
SIGKILL (9)andSIGSTOP (19)cannot be caught, blocked, or ignored, guaranteeing the OS can always terminate or stop a process.
Sending signals:
Bashkill -SIGTERM 4521 # graceful kill -9 4521 # force kill kill -l # list all signalsSignals thus provide a flexible way to control process behavior and enable robust process management.
That's unit 8
Long answers stick best when they're tested again soon. Run the MCQs on this unit, then come back to the questions you found hardest.
Nearly through. Did unit 8 of CSE105 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 8 of CSE105 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill; the rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks.