hardMultiple ChoiceObjective-mapped
XK0-006 Practice Question: A Linux administrator is responsible for a…
A Linux administrator is responsible for a critical application that runs as a systemd service on a server. The application occasionally hangs, and the administrator wants to automate the restart if the service becomes unresponsive. The administrator writes a Bash script that checks if the service is active and responsive by pinging a local health endpoint. If the health check fails three consecutive times, the script restarts the service. The script is intended to run every minute via a cron job. However, after implementing the cron job, the service is restarted even when it is functioning correctly, causing unnecessary downtime. The administrator reviews the script and finds the following logic:
#!/bin/bash SERVICE="myapp" COUNT_FILE="/tmp/${SERVICE}_failcount"
if curl -f http://localhost:8080/health; then
echo 0 > "$COUNT_FILE" else FAILS=$(cat "$COUNT_FILE" 2>/dev/null || echo 0) FAILS=$((FAILS + 1)) echo "$FAILS" > "$COUNT_FILE"
if [ "$FAILS" -ge 3 ]; then
systemctl restart "$SERVICE" echo 0 > "$COUNT_FILE" fi fi
What is the most likely cause of the false restarts?
⚠ Common exam trap
CompTIA often tests the misconception that a missing file or permission error is the root cause, when in reality the issue is a race condition from overlapping cron job executions.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Multiple instances of the script are running concurrently due to cron timing, causing a race condition on the count file.
The cron job runs the script every minute, but if the health check takes longer than a minute (e.g., due to network latency or a slow endpoint), multiple instances of the script can overlap. Each instance reads, increments, and writes the count file independently, causing a race condition where the fail count can be artificially inflated, leading to a false restart even when the service is healthy.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The count file is not being written because the script lacks write permissions to /tmp.
Why it's wrong here
If that were the case, the script would fail to write, and the count would never increment, so restarts would not occur.
- ✓
Multiple instances of the script are running concurrently due to cron timing, causing a race condition on the count file.
Why this is correct
Without file locking, concurrent runs can overwrite each other's counts, leading to inaccurate failure counts and false restarts.
- ✗
The script does not reset the count file after a successful health check.
Why it's wrong here
The script does reset the count file to 0 on success; that part is working correctly.
- ✗
The script does not handle the case where the count file does not exist on the first failure.
Why it's wrong here
The script uses $((FAILS + 1)) and cat with default, which handles missing files correctly.
Go deeper
Related to this question
Learn chapter
Linux Fundamentals and History
Key term
Bash
Bash is a command-line interpreter that lets users interact with an operating system by typing text commands instead of clicking icons.
Key term
Service
A service is a software component or system that performs a specific function and is available to be used by other programs or users over a network.
About these practice questions
This XK0-006 question is part of Courseiva's 979-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This XK0-006 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the XK0-006 exam.