替换Linux中正在运行的可执行文件 [英] Replacing a running executable in linux

查看:456
本文介绍了替换Linux中正在运行的可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌入式Linux系统,可以从USB卡进行自我更新.接口程序检测到USB插入,并查找升级的可执行文件.我目前将其复制到本地文件,并在rc5.d中安装一些命令,以在下次启动时通过现有exe复制该文件.然后,我重新启动了软件.

I have an embedded linux system that can update itself from a USB card. The interface program detects the USB insertion and looks for the upgraded executable. I currently copy it to a local file and install some commands in rc5.d to copy the file over the existing exe on the next boot. Then I have the software reboot.

有更好的方法吗?

推荐答案

在下一次启动时,不需要让它复制文件.相反,此序列可以正常工作:

You don't need to have it copy the file over on next boot. Instead, this sequence will work fine:

  • 将新的可执行文件复制到本地文件.
  • 验证本地文件.
  • unlink()现有可执行文件.
  • 将新的可执行文件重命名()为正确的名称.

unlink()之后,应用程序将继续运行-内核将不会释放基础数据,直到所有执行中的副本完成.

The application will keep running after the unlink() - the kernel won't release the underlying data until all executing copies are finished.

您甚至可以只使用execve()将当前正在运行的进程替换为新上载的版本.

You can then even just use execve() to have the currently-running process replace itself with the newly uploaded version.

这篇关于替换Linux中正在运行的可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆