1

On CentOS 6.3, In my main program I mount a Truecrypt volume containing executables A and B to a mount point, ./tmpfolder. I run program A, by doing

system("./tmpfolder/A")  

from a forked child.

Program A does:
if (fork() == 0){
system("cp ./tmpfolder/B /tmp");
chdir("/tmp");
execl("/tmp/B", "B", (char *)0);
exit(0);
}

At this point program A exits, leaving program B running. So far so good.

Program B does:
chdir ("/tmp");
while(notdone){ /* do stuff */ }

Now I want to unmount the Truecrypt volume while leaving program B running. I cannot; the folder is in use.

After running A, ps shows B running, with PID 27643 (for example).
Then ls -l /proc/27643/cwd shows "/tmp". So the current working directory of B is not the mount point folder.

But my attempt to unmount fails: "device is busy".
And fuser -c ~/tmpfolder shows 27643, the PID of program B. So, somehow, program B is still using the mount point folder.

How can program B be still using the folder in which program A ran and then exited? How can I launch B without having it use the mount point folder?

mike scholtes
  • 173
  • 2
  • 9
  • 1
    Copying it (and changing current directory to) somewhere like /tmp should work. The reason the mount is locked is because the executable is `mmap`ed in, so the OS will need the file to stay open until the executable finishes. But if it's on a different path, it should be no problem. – Mats Petersson Aug 04 '13 at 22:42
  • It could as well be the current working directory. Go to /proc/ and look where the cwd symlink is pointing to, in this case a simple chdir() might already solve that issue. – amo-ej1 Aug 05 '13 at 11:39

0 Answers0