CompTIA Linux+ free question 4 / 10 · Domain 2: Services and User Management
Two Java services run on a host, and both processes are named java. Only the command line of the billing service contains the text billing.jar. Which command ends just the billing service?
- pkill -n billing.jar, which selects the newest of the matching processes
- pkill -e billing.jar, which displays the name and PID of the process that is killed
- pkill billing.jar, which matches the pattern against the process name
- pkill -f billing.jar, which matches the pattern against the full command line
Show the answer and explanation
Answer: D
Why this is correct
The pkill(1) page says the pattern is normally only matched against the process name, and that when -f is set the full command line is used. Both services are named java, so only the command line can tell them apart. pkill -f billing.jar therefore signals the billing service and leaves the other one running.
Why the other options are wrong
"pkill billing.jar, which matches the pattern against the process name" … The page says the pattern is normally matched against the process name, which is java for both services. A pattern taken from the command line finds no process without -f.
"pkill -e billing.jar, which displays the name and PID of the process that is killed" … The page describes -e as echoing the name and PID of the process being killed. It does not change what the pattern is compared with.
"pkill -n billing.jar, which selects the newest of the matching processes" … The page describes -n as selecting the most recently started of the matching processes. The matching itself still uses the process name, so billing.jar finds nothing.
Key points
pkill and pgrep match the process name unless -f is given. -n and -o pick the newest or oldest match, -x asks for an exact match, and -e only reports what was signaled.
Go to the CompTIA Linux+ practice app (10 free questions; purchase unlocks all questions)