There can be several mount points under management in linux. I want to umount them all or don’t umount any. Since there are cases when linux cannot umount a device (like someone is on the mount point), I want to add a function to check all mount points and see if the devices can be umounted before I actually perform umount action.
Is there any functions like trylock
to test if a device is umountable? Or if there are any function to check if any user is using the mount point like lsof
?
Advertisement
Answer
There isn’t a way, AFAIK. And that’s ok because your idea is flawed, it’s a classic case of a TOCTOU race condition. Between checking whether umount()
would succeed and actually performing it, any other process might change the outcome.