Is it safe to recompile an executable while it's running?

后端 未结 8 2170
再見小時候
再見小時候 2020-12-24 06:36

What happens if I recompile an executable while it\'s running? Does the operating system read all of the executable\'s contents into memory when it starts running it, so it

8条回答
  •  时光说笑
    2020-12-24 07:07

    In Windows you can't delete a locked file but what most people don't know is that you can move or rename a running exe.

    So you could

    • move the old exe to a temp directory on the same drive
    • schedule it for deletion on the next reboot: MoveFileEx(name, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
    • move a new exe in its place.

    The old program will keep running but new processes will use the new file.

提交回复
热议问题