question about running executable and recompilation

This is a discussion on question about running executable and recompilation within the C++ Programming forums, part of the General Programming Boards category; Hi, While I am running an executable, I modify and compile the program that regenerate the executable. Will the current ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    159

    question about running executable and recompilation

    Hi,
    While I am running an executable, I modify and compile the program that regenerate the executable. Will the current running of the old executable be affected? Will this habit cause any potential bad effect?
    Thanks and regards!

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You may not actually be able to modify the exe while it is running.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    Yes, I can. I am programming in Ubuntu8.10 with gcc as compiler

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    In Windows you can't. In Linux you can (All hail for Linux!)

    No. It won't harm your program's execution, unless your program just happens to read directly from the current application. But there should be no reason to do such a thing, except maybe for an auto-unzip-like feature.
    Sorry, I'm going into too much depth.
    No, it doesn't matter. The executable is loaded into the memory upon executing it. Whatever you change on the hard drive will only be loaded into the (executing) memory when you next execute it.
    Identically, you can remove any file that's being executed whenever you want to.

    Just for fun:
    # cp /bin/rm /bin/rm2
    # rm /bin/rm
    # rm /etc/passwd
    bash: /bin/rm: No such file or directory
    # cp /bin/rm2 /bin/rm

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    147
    Pardon me for adding....

    ...it's one of the little discussed differences in the way these OS work under the hood.

    Windows doesn't load the executable into RAM, entirely, when it executes, which makes Windows dependent on the executable, and therefore locks it from your ability to overwrite. *nix loads into RAM, like EVOEx said.

    What Windows is doing is to use the executable file as a memory mapped file: the executable content is paged in as a result of paging errors encountered as execution proceeds, which is why it must be locked and you can't write out an alternate executable.

    In some IDE/debuggers, you can stop execution at a breakpoint, make code changes, let it compile and continue execution without having shut the target application down. It is occasionally even more useful than what you're doing.

  6. #6
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    Thanks EVOEx and JVene!

    Quote Originally Posted by JVene View Post
    In some IDE/debuggers, you can stop execution at a breakpoint, make code changes, let it compile and continue execution without having shut the target application down. It is occasionally even more useful than what you're doing.
    Do you mean VC++ in Windows? I programed a little in VC++ a year ago. I remember it is the Edit and Continue feature in its debugger. Is there something equivalent in Linux, e.g. for gdb?

    Also in Linux an executable can be executed in multiple different processes at the same time. Is this the same thing for Windows?

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by lehe View Post
    Also in Linux an executable can be executed in multiple different processes at the same time. Is this the same thing for Windows?
    Yes, you can run the same executable many times, thus getting more than one process running at the same time from the same executable file.

    And on the VERY pedantic side:
    In linux (and other versions of Unix), starting an executable does NOT load all of it into memory - the file is demand loaded, that is, the first part of the executable is loaded, then it loads the remaining portions as it needs them - just like Windows does. The reason you can recompile an application whilst it is currently running is that the regular file-system(s) in Linux do not ACTUALLY delete the file until all references to that file are gone - so if the file is held open (which it is when it is being executed, by the OS itself), it will not actually be deleted - it's just removed from the directory entry.

    The reason Windows can't modify an executable file is that to create a new file, the old file has to be deleted. Since Windows is also holding the executable file open (so that it can load the parts of the file that it may not have loaded yet).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    Thanks matsp!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21