#!/bin/sh set -e MNT=testmnt # Create a new namespace and bind-mount it to keep it alive. ( touch "$MNT" unshare --net mount --bind /proc/self/ns/net "$MNT" ) rm -f barrier && mkfifo barrier # Hold a reference while the namespace gets unmounted. ( exec 4<"$MNT" ls -l /proc/self/fd cat < barrier ls -l /proc/self/fd ) & # Unmount the namespace while there's still a reference. cat /dev/null > barrier umount --lazy "$MNT" wait