Question 530
In a hands-on RHCSA practice VM, the assigned outcome was: A maintenance script must report whether a given process name exists without exiting with a misleading success status. What specific verification would demonstrate the target state?
Explanation
Correct Answer
The known present and missing fixture processes produce different status messages. This check confirms the expected effect of: Use `if pgrep -x "$1" >/dev/null; then echo running; else echo absent; fi` after argument validation. It distinguishes the intended result from the original failure mechanism: An exact process-name match requires `-x` instead of a broad substring search.
Incorrect Answers
A fixture containing backslashes is printed unchanged and no unexpected interpolation occurs. That verifies a separate lab task: A script asks users for a name but accidentally treats backslash sequences in the input as control codes. It does not validate the implementation required here: Use `if pgrep -x "$1" >/dev/null; then echo running; else echo absent; fi` after argument validation.
The script runs under a restricted environment and resolves required binaries. That verifies a separate lab task: A cron-invoked script prints `command not found` for a utility present in the interactive user's shell. It does not validate the implementation required here: Use `if pgrep -x "$1" >/dev/null; then echo running; else echo absent; fi` after argument validation.
Arguments containing spaces are printed as single intended entries and the loop count matches input count. That verifies a separate lab task: A housekeeping script must print each user-provided directory rather than always print one hard-coded value. It does not validate the implementation required here: Use `if pgrep -x "$1" >/dev/null; then echo running; else echo absent; fi` after argument validation.