在程序执行期间编辑源代码
我有一个 C 程序,它从不同的文件调用多个函数,在编译过程中,我将所有目标文件链接在一起以生成二进制文件。然后我开始执行程序。现在我想编辑各种文件的源代码并编译新版本。这将覆盖旧的对象和二进制文件。
这样做会影响当前程序的执行吗?现在它会链接新的目标文件吗?如果我覆盖正在运行的二进制文件,这是否会导致执行停止,或以其他方式影响它?或者代码是否存储在执行开始时无法被覆盖的地方?
我正在使用 gcc 来编译我的代码。
I have a C program which calls several functions from different files, and in compilation I link all the object files together to make the binary. I then start execution of the program. Now I would like to edit the source of various files and compile the new versions. This will overwrite the old object and binary files.
Will doing this affect execution of the current program? Will it now be linking the new object files? If I overwrite the binary being run will this cause execution to be halted, or impact it in some other way? Or is the code stored in a place where it cannot be overwritten at the start of execution?
I'm using gcc to compile my code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Unix 上,让
gcc
替换可执行文件不会对正在运行的程序产生影响。它的工作方式是,只要程序运行,旧的可执行文件就会保留在磁盘上,以便操作系统可以在需要时引用它。将不再有指向旧可执行文件的目录条目,并且当程序的旧实例停止时,磁盘空间将被回收。
On Unix, letting
gcc
replace the executable will have no impact on the running program.The way it works is that the old executable will remain on disk for as long as the program is running, so that the operating system can refer to it if needed. There will no longer be a directory entry pointing to the old executable, and the disk space will be reclaimed when the old instance of the program stops.