I have a broad question:
Suppose that I have a C++ program and I started to run it on a file in the background with some configuration which can be set internally. While it was running, I changed these internal configurations, compiled it and started to run it on another file.
Is this going to affect the previous instance which was already running in the background ? or since it was already up and running it won’t ? Any ideas on this is appreciated.
It is not safe to modify an executable that is running. As per What happens when you overwrite a memory-mapped executable?
If you delete the file and compile a new version of the program then what will happen is very well defined. The already running instance will use the previous code, and that will be held in memory by the operating system until the program terminates. Any new instances will use the new code.
The summary: You should make sure your build system deletes the old executable before recompiling, and so long as that is true then the recompile will not take effect until you rerun the program, otherwise the behaviour is undefined (read SIGSEGV).
Appendix of sorts:
JamesKanze rightly pointed out that the linker itself may delete the file before writing its output, if this is the case then it will always behave as if you’d deleted the file yourself before recompiling (the sane scenario). Looking at bfd/cache.c from the binutils cvs head:
So at least with GNU LD this is guaranteed to be fine. This does not necessarily extend to other linkers, however.