Courseiva
mediumMultiple Choice

XK0-006 Practice Question: A developer needs to run a one-time script after…

A developer needs to run a one-time script after the network is up on a systemd-based server. Which unit type should be used?

⚠ Common exam trap

Candidates often confuse `oneshot` with `simple` or `forking`, mistakenly thinking a one-time script needs to remain running (`simple`) or fork into the background (`forking`), but systemd's `oneshot` is explicitly designed for tasks that exit after completion.

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

✓

oneshot

The `oneshot` unit type is correct because it is designed for services that run a single task to completion and then exit, making it ideal for a one-time script that must execute after the network is up. In systemd, `oneshot` units can be configured with `RemainAfterExit=no` (the default) to indicate they do not need to stay running, and they support ordering dependencies like `After=network-online.target` to ensure the network is available before the script runs.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    forking

    Why it's wrong here

    Forking describes a service whose parent process exits after spawning children, so systemd tracks the wrong PID; it is a service Type value, not a unit type, and cannot express a one-time run. It would suit a daemonising service, but the scenario needs a oneshot unit ordered after network-online.target.

  • ✗

    exec

    Why it's wrong here

    Exec is not a systemd unit type; it names directives such as ExecStart inside a unit file. It is tempting because the script is executed via ExecStart, but the question asks which unit type schedules a one-time run, and only a oneshot service unit does that after network-online.target.

  • ✗

    simple

    Why it's wrong here

    Simple is a service Type value where systemd assumes the process started immediately; it is not a unit type and does not mark the unit complete. It suits long-running daemons, whereas a one-time script needs Type=oneshot with RemainAfterExit and ordering after network-online.target.

  • ✓

    oneshot

    Why this is correct

    A oneshot unit runs a command to completion and then exits, which suits a one-time script rather than a long-running daemon. Pairing it with `After=network-online.target` and `Wants=network-online.target` satisfies the stem's requirement that the script execute only once the network is up.

About these practice questions

One of 781 original XK0-006 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.