Astounding that that works, vino! Looking at the
Linux man page for unlink(2), I see that it does not detect "text busy". Compare that to the
HP-UX man page for unlink(2). The Linux unlink(2) is rather permissive. If that man page is right, it even allows unlinking an active mount point! I'm not sure what effect that would have... Posix does not require that unlink(2) disallow unlinking mount points (but the text in the standard makes it clear that this is because Posix does not ever mention mount points). But unlinking an active program is another matter. On one hand, the
Posix Standard says:
Quote:
The unlink() function shall fail and shall not unlink the file if:
...
[ETXTBSY] The entry to be unlinked is the last link to a pure procedure (shared text) file that is being executed.
That sounds to me like an OS is required to disallow the operation. But toward the end of the page we have:
Quote:
The [ETXTBSY] optional error condition is added.
This leaves me confused as to whether or not the operation is allowed by Posix. But it will not work on most implementations of Unix. I would be interested if this program works with any kernel other than Linux.
A more portable solution would be have the program to write a little shell script to unlink the file and then exec that shell script.