back to labs
Capture a Background Job's PID with $!
MediumCommand Line Essentials10-15 minThe brief
Backgrounding a job is only half the story — to manage it later you need its PID. The program /usr/local/bin/collector.sh runs until killed; it isn't running yet.
Start it in the background AND write its process id to the file /root/collector.pid (just the PID number), so an ops script can stop it later with kill "$(cat /root/collector.pid)".
Grading checks that the collector is running and that /root/collector.pid holds THAT process's real PID — a guessed number won't pass, and neither will the PID of some other process.
What you'll do
- Start /usr/local/bin/collector.sh in the background
- Record the backgrounded job's PID to /root/collector.pid
- Ensure the recorded PID is the collector's actual, running PID
Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.
