If you know where the program is stored on disk, you can exec() execute the program:
char args[] = { "/opt/somewhere/bin/program", 0 }; execv(args[0], args); fprintf(stderr, "Failed to reexecute %s\n", args[0]); exit(1);
If you don't know where the program is located on disk, either use execvp() to search for it on $ PATH, or find out. On Linux, use the /proc - and /proc/self/exe ; this is a symbolic link to the executable, so you will need to use readlink() to get the value. Beware: readlink() not null, terminates the line it is reading.
If you want, you can arrange for the transfer of an argument that tells the new process that it restarts after the update; the list of available minimum arguments that I have provided can be as complicated as you need (a list of files currently open for editing, perhaps, or any other relevant information and options).
Also, be sure to clear before re-executing - for example, close all open files. Remember that open file descriptors are inherited by the executable process (if you did not mark them for closing on exec using FD_CLOEXEC or O_CLOEXEC ), but the new process will not know what they are for, unless you say so (in the argument list), therefore, he cannot use them. They will simply clutter up the process without helping at all.
source share