
Here's some of the basic code inside a script called test.sh
.
bash -c "sleep 10; echo \$(pidof unshare)" &
sudo unshare --mount --uts --ipc --net --pid --fork /bin/sh -c "
... do stuff ...
sleep 60
" &
PID=$!
When I execute the script, the process IDs identified by the background bash command on the first line and the value assigned to PID are different. Additionally, if you run a ps
in the script, I don't see either of those process IDs. I'm guessing that I'm passing the code to unshare incorrectly to make it all run as a single process in the background? How can I get the actual PID of the process running in the background in the new namespace?