While reviewing a Bash script that cron runs nightly, you notice that ps lists both the script's /bin/bash process and the long-running /usr/local/bin/backup.sh process it launches. You want the cron-spawned PID to be replaced by backup.sh so that no extra shell remains and any signals sent to the original PID go directly to backup.sh. Which change to the script accomplishes this without spawning an additional process?
The shell built-in exec overlays the current shell with the specified program; it does not fork a new process, so the PID remains the same and control never returns to the shell after the replacement command ends. Writing exec /usr/local/bin/backup.sh therefore makes the cron-started Bash process turn into backup.sh, eliminating the extra sleeping shell.
All other choices start a new process:
Running with nohup and an ampersand spawns a child process that survives hang-ups but leaves the parent shell intact.
Using an ampersand followed by disown also backgrounds the job, then detaches it from the shell-yet the shell process still exists until it exits.
env -i starts a command with an empty environment but, like any ordinary command, is executed in a child process forked from the shell.
Only the exec form replaces the current shell in-place.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the 'exec' command do in a Bash script?
Open an interactive chat with Bash
Why is using 'nohup' not equivalent to 'exec' in this case?
Open an interactive chat with Bash
What are the drawbacks of using 'env -i' to clear the environment?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Services and User Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .