Managing Processes
This section covers core Linux process management, job control, signal handling (kill, pkill, killall), scheduling priority manipulation (nice, renice), and system performance profile tuning using tuned for RHCSA preparation.
Theory Questions
1. What distinguishes lightweight threads from full processes in Linux?
Linux implements threads as Lightweight Processes (LWP) that share memory and resources within the same process group.
- Command(s):
ps -eLf - Why:
ps -eLfdisplays individual threads under theLWP(Lightweight Process ID) column, alongside the parentPIDand total thread count (NLWP). - Gotchas: Confusing an LWP thread with an independent process. In Linux, threads belonging to the same process share identical memory address spaces and PID/TGIDs.
- Verify:
ps -eLf | head -n 10
2 & 12. How do you stop a foreground job and continue running it in the background?
Suspend the active job with Ctrl + Z, then send it to the background using bg.
- Command(s): Press
Ctrl + Z, then typebg %<job_number>(or simplybg) - Why:
Ctrl + ZsendsSIGTSTPto pause execution, andbgsendsSIGCONTto resume process execution in the background. - Gotchas: Leaving a job suspended via
Ctrl + Zwithout runningbgkeeps the process in aStoppedstate rather than actively running. - Verify:
jobs -l(status should displayRunning).
3. How do you terminate an active interactive foreground shell job using a keyboard shortcut?
Send an interrupt signal to the running process by pressing Ctrl + C.
- Command(s): Press
Ctrl + C - Why: Sends
SIGINT(Signal Interrupt, signal 2) to the active foreground process, instructing it to terminate immediately. - Gotchas: Pressing
Ctrl + Zsuspends the process in memory instead of stopping or canceling it. - Verify: The terminal returns directly to a blank shell prompt, and
jobsdisplays no active background tasks.
4. How are execution threads managed and represented in Linux kernel scheduling?
Threads share virtual memory pointers, file descriptors, and signal handlers while maintaining individual LWP identifiers.
- Command(s):
ps -eLfortop -H - Why: The Linux kernel schedules tasks using
task_structobjects. Threads are tasks that share execution contexts with parent processes. - Gotchas: Assuming threads possess completely isolated memory boundaries like standard fork child processes.
- Verify:
ps -eLf | grep <process_name>
5. How do you retrieve full execution commands and start arguments for a running process?
Query process details using ps -f -p or read /proc/<PID>/cmdline.
- Command(s):
ps -f -p <PID>orcat /proc/<PID>/cmdline | tr '\0' ' ' - Why:
ps -fformats full command arguments, while/proc/<PID>/cmdlinereads the raw memory vector passed during process launch. - Gotchas: Running basic
ps -p <PID>truncates long command-line arguments and option flags. - Verify:
ps -f -p $$
6. What nice value range controls process scheduling priority, and how do values affect execution?
Nice values range from -20 (highest priority) to 19 (lowest priority), defaulting to 0.
- Command(s):
ps -el - Why: Lower numerical nice values instruct the kernel CPU scheduler to allocate larger time slices to the process.
- Gotchas: Assuming higher positive nice numbers grant higher execution priority; positive numbers make a process nicer to others, yielding CPU cycles.
- Verify:
ps -eo pid,ni,pri,comm
7 & 15. How do you change the scheduling priority of an active process by PID?
Modify runtime process priority using the renice command.
- Command(s):
sudo renice -n -5 -p <PID> - Why:
reniceupdates the nice value of active processes without requiring a service restart.-nspecifies the new value and-ptargets the PID. - Gotchas: Regular users can only increase nice values (lower priority). Setting negative nice values (higher priority) requires root privileges via
sudo. - Verify:
ps -p <PID> -o pid,ni,comm
8. Which Linux administrative commands send signals to system processes?
Commands like kill, killall, pkill, and top send signals to processes.
- Command(s):
kill -l - Why:
killtargets PIDs,killalltargets exact process names, andpkilltargets regular expression match patterns. - Gotchas: Shell job controls (
fg,bg,jobs) manage session task states but do not send arbitrary custom IPC signals. - Verify:
kill -l
9. How do you alter the nice value of a process interactively from inside top?
Press r while viewing the top interactive interface.
- Command(s): Press
rinsidetop, input the target<PID>, and specify the new<nice_value>. - Why: Launches the built-in
toprenice prompt to modify scheduler settings dynamically. - Gotchas: Supplying a nice value outside the valid
-20to19boundary causestopto reject the change or cap it at threshold limits. - Verify: Observe the updated value under the
NIcolumn intop.
10. How do you apply the powersave performance profile using tuned?
Activate power-saving settings using tuned-adm profile.
- Command(s):
tuned-adm profile powersave - Why:
tuned-admapplies system-wide tuning profiles adjusting CPU governor limits, disk spin times, and bus power management. - Gotchas: Modifying profiles via
systemctlis unsupported; always use thetuned-admCLI utility. - Verify:
tuned-adm active
11. How do you list active shell jobs along with their corresponding PIDs?
Run jobs -l within the current shell session.
- Command(s):
jobs -l - Why:
-ldisplays job IDs, execution states (Running,Stopped), and assigned process IDs (PIDs). - Gotchas:
psshows system-wide processes, whereasjobstracks background tasks tied exclusively to the active shell session. - Verify:
jobs -l
13. How do you terminate all processes belonging to another user account?
Use pkill -u or elevated kill signals.
- Command(s):
sudo pkill -u <username>orsudo kill -9 <PID> - Why:
pkill -umatches and sendsSIGTERMsignals to all processes owned by the designated target UID. - Gotchas: Standard user accounts cannot signal processes owned by other users; root permissions are required.
- Verify:
pgrep -u <username>
14. How do you view parent-child process relationships in a visual tree layout?
Execute pstree or format ps output using tree options.
- Command(s):
pstree -porps -ef --forest - Why: Renders hierarchical tree structures showing parent process IDs (PPID) and spawned child process branches.
- Gotchas: Standard flat process lists (
ps aux) mask process lineage relationships. - Verify:
pstree -p | head -n 20
16 & 17. How do you stop all running process instances matching a specific command name?
Use killall or pkill targeting the process name string.
- Command(s):
killall ddorpkill dd - Why:
killallsends termination signals to all processes matching an exact name, whilepkillmatches substring patterns. - Gotchas:
killallrequires an exact name match. Usingpkillwith overly broad patterns may accidentally terminate unintended system services. - Verify:
pgrep dd(returns no output if all instances are terminated).
18. How do you terminate a process interactively from inside top?
Press k within the top interactive interface.
- Command(s): Press
kinsidetop, enter the target<PID>, and specify the signal number (default is15forSIGTERM). - Why: Allows administrative termination of offending processes directly from the interactive monitor.
- Gotchas: Pressing Enter without specifying a signal sends default
15(SIGTERM). Use signal9(SIGKILL) if the process refuses to stop. - Verify: Confirm the target process entry vanishes from the active
topdisplay table.
19. How do you view system tuning recommendations and apply the suggested profile using tuned?
Query system recommendations using tuned-adm recommend and apply the result.
- Command(s):
tuned-adm recommendfollowed bytuned-adm profile <profile_name> - Why:
recommendevaluates hardware architecture, virtualization layers, and workload characteristics to determine optimal settings. - Gotchas: Selecting profiles without evaluating system role recommendations may result in suboptimal performance or excessive power draw.
- Verify:
tuned-adm active
Lab Tasks
Process Management Practice
Manage background jobs, modify runtime nice values, perform bulk process termination, and enable dynamic performance profiles.
Configuration Steps
# 1. Launch three background dd processes
dd if=/dev/zero of=/dev/null &
dd if=/dev/zero of=/dev/null &
dd if=/dev/zero of=/dev/null &
# 2. Extract the PID of the first background job
TARGET_PID=$(jobs -p | head -n 1)
# 3. Increase process priority by setting nice value to -5
sudo renice -n -5 -p $TARGET_PID
# 4. Further increase process priority by setting nice value to -15
sudo renice -n -15 -p $TARGET_PID
# 5. Terminate all active dd process instances
killall dd
# 6. Install, enable, start, and configure the tuned performance service
sudo dnf install tuned -y
sudo systemctl enable --now tuned
sudo tuned-adm profile throughput-performance
-
Why:
-
Trailing
&places commands directly into the background, returning control to the terminal. -
renicedynamically updates process priority without stopping running jobs. -
killallsends defaultSIGTERMsignals to all matching binary names simultaneously. -
systemctl enable --nowstarts thetuneddaemon immediately and configures automatic boot startup. -
tuned-adm profile throughput-performanceapplies optimizations for high-throughput server workloads. -
Gotchas:
-
Setting negative nice values without
sudoprivileges returns aPermission deniederror. -
Forgetting to run
systemctl enableleaves thetunedservice inactive after system reboot.
Verification Procedures
Validate background job states, priority modifications, process terminations, and active tuning profiles.
# Verify active tuned profile selection and daemon status
tuned-adm active
systemctl is-active tuned
# Verify all dd background processes have terminated
pgrep dd