Linux Process Management 5 — Questions and Answers
Question 1: What does 'strace -p PID' do?
- Shows the process's stack trace
- Attaches to a running process and traces its system calls (Correct answer)
- Displays process statistics in real time
- Streams the process's stdout output
Correct answer: Attaches to a running process and traces its system calls
strace -p attaches to an already-running process and prints every system call it makes, useful for debugging hangs or unexpected behavior.
Question 2: Which scheduling policy gives a process guaranteed CPU time slices in a real-time manner?
- SCHED_OTHER
- SCHED_IDLE
- SCHED_FIFO (Correct answer)
- SCHED_BATCH
Correct answer: SCHED_FIFO
SCHED_FIFO is a real-time scheduling policy where a process runs until it yields or is preempted by a higher-priority real-time process.
Question 3: What information does 'cat /proc/PID/status' provide?
- Only the process exit code
- Human-readable process metadata including state, memory, and UIDs (Correct answer)
- The process's network connections
- The process's open file descriptors
Correct answer: Human-readable process metadata including state, memory, and UIDs
/proc/PID/status provides a human-readable summary of process state, memory usage, thread count, and real/effective UIDs.
Question 4: What happens when a process calls exec() after fork()?
- A new child process is created
- The current process image is replaced with a new program (Correct answer)
- The parent process is terminated
- Both parent and child load the new program
Correct answer: The current process image is replaced with a new program
exec() replaces the calling process's memory image with a new program, keeping the same PID but running entirely new code.
Question 5: Which command shows real-time per-process I/O statistics?
- iostat -p
- iotop (Correct answer)
- lsof -io
- vmstat -d
Correct answer: iotop
iotop displays a top-like interface showing disk read/write rates per process in real time.
Question 6: What does setting OOM score adjustment (oom_score_adj) to -1000 for a process do?
- Makes the process the first target for the OOM killer
- Makes the process completely immune to the OOM killer (Correct answer)
- Doubles the process's memory allocation limit
- Triggers immediate memory compaction for the process
Correct answer: Makes the process completely immune to the OOM killer
An oom_score_adj of -1000 disables OOM killing for that process, used to protect critical system daemons from being killed under memory pressure.
Question 7: Which command can be used to run a process in a specific CPU affinity set (bind it to certain cores)?
- cpuset
- taskset (Correct answer)
- numactl --cpunodebind
- cputask
Correct answer: taskset
taskset sets or retrieves the CPU affinity mask for a process, allowing you to bind it to specific CPU cores.
What does 'strace -p PID' do?