I am running Linux.
I have a single process in a mount namespace.
I did in this process a mount -t tmpfs tmpfs /mountpoint
.
What happens if the process exits and there are no more processes in that mount namespace?
Will the filesystem be automatically unmounted?
Will the mount namespace be destroyed?
If the namespaces and the mount are still active how do I access it?
What happens to tun/tap/macvtap interfaces if a network namespace has no more processes?
Best Answer
I was wondering the same thing, and so I ran a little test (on kernel 4.20.0, using unshare from util-linux 2.33; the manpage for unshare in that version has some notes on shared/private mounts that are worth reading, and YMMV if you are using an older version).
TL;DR: Yes, the filesystem is unmounted when the last process in the namespace exits.
In my case, the device I'm testing with is
dm-6
, and it is not mounted in the "outer" namespace.Window 1:
Window 2: Window 3: Do the same thing as window 1.Window 1:
Window 2: Exit the
unshare
environmentWindow 1: Check again,
dm-6
is still thereWindow 3: Exit the
unshare
environmentWindow 1: Check again,
dm-6
is gone againAnother useful demo / test: Similar idea, but instead of having 3 windows, enter and exit Window 2 twice. Check
dmesg
or logs, and verified that the kernel message that it mounted the filesystem appears twice in this case.