No cleanly. You can, for example, remove a USB you are running software from. If the program does not need any resources from there, then nothing will happen but it will not exit cleanly.
$ sudo dd if=/dev/zero of=/tmp/disk bs=1M count=100
$ sudo mkfs -t ext4 /tmp/disk
$ sudo mount /tmp/disk /mnt
$ sudo cp -a /bin/bash /mnt/newbash
$ /mnt/newbash
If you go to another terminal and try to umount /mnt
the system will tell you it is busy, and fuser -m /mnt
will list newbash as the process using it, also lsof
.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
newbash 903 root txt REG 7,0 1168776 12 /mnt/newbash
Even though the filesystem is in use, you could do umount --lazy /mnt
BUT that could have nasty consequences. You don't know if the whole executable is in memory and the system might need to fetch a part of it for example.
It would be asking for trouble. The option is there to avoid wait forever on resources you no longer have access to, for example at shutdown.
If all you want is to run it on memory, then you could create a ramdisk, copy it there and run it.
You could even setup something like encfs so that the folder in the ramdisk is encrypted.