This depends entirely on the behaviour of your process when using its temporary storage.
If your process holds a file open on /mnt
, then you can't replace the device without causing the process to most probably fail in some undefined way, even if you manage to force-unmount the device. Processes generally don't expect devices on which they have open files to disappear.
If your process opens, writes to, and then closes files on /mnt
, you might be able to get away with stopping it, unmounting and remounting /mnt
, and restarting it. This depends on your being able to stop the process while it's not using /mnt
. So you could
$ kill -STOP pid
$ lsof -p pid | grep /mnt
... then, if it has nothing open on /mnt ...
$ sudo umount /mnt
$ sudo mount /dev/sdb1 /mnt
$ kill -CONT pid
This won't necessarily work even if you stop the process with no files open on /mnt
, because you might have interrupted some logic which relies on /mnt
not changing; something like
- Check if
/mnt/wibble
exists
- It does! Let's get ready to open and read from it
- ...process stops, and a different device gets mounted on
/mnt
...
- ...process restarts...
- Oh no!
/mnt/wibble
can't be opened!
- Die horribly