In my C ++ application, my execv() application in the fork() ed child process uses the same executable to handle some work in the new child process with different arguments that communicate with the channels in the parent process. To get the name of the path to myself, I execute the following code on the Linux port (I have different code on the Macintosh):
const size_t bufSize = PATH_MAX + 1; char dirNameBuffer[bufSize]; // Read the symbolic link '/proc/self/exe'. const char *linkName = "/proc/self/exe"; const int ret = int(readlink(linkName, dirNameBuffer, bufSize - 1));
However, if, at runtime, I replace the executable with an updated version of the binary on disk, the result of the readlink() : "/usr/local/bin/myExecutable (deleted)"
I understand that my executable has been replaced with a newer updated version, and the source for /proc/self/exe now replaced, however, when I go to execv() , it now fails with errno 2 - No such file or directory. to additional trailing " (deleted)" as a result.
I would like execv() use the old executable for itself or updated. I can simply identify the line ending in " (deleted)" and change it to omit this and allow the updated executable, but that seems awkward to me.
How can I execv() execute the current executable (or replace it if it's easier) with a new set of arguments when the original executable was replaced with an updated one at runtime?
c ++ linux fork exec self-reference
WilliamKF
source share