c++启动新进程并终止现有进程
我希望能够让更新程序应用程序启动应用程序的新版本,然后自行终止。
当我尝试通过“系统”调用新应用程序的“通常”方式时,更新程序永远不会退出。
想法?
I want to be able to have an updater application launch the new version of the application, then terminate itself.
When I try the 'usual' of calling the new application via 'system', the updater never exits.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 Windows 上的 CreateProcess 或 < Unix 上的 href="http://linux.about.com/od/commands/l/blcmdln_exec.htm" rel="nofollow">exec 。使用宏创建操作系统特定代码的包装器。
Look into CreateProcess on Windows or exec on Unix. Use macros to create a wrapper over the OS specific code.
exec 函数系列用新进程替换当前进程。如果 fork 后没有从子进程调用,这应该用新程序替换您的程序。
系统调用 fork,然后在子进程中执行 shell 并等待其返回,这就是您的更新程序不退出的原因。
请参阅 man 3 exec 和 man 3 system。
exec family of functions replaces current process with a new one. If not called from child after fork, this should replace your program with new one.
system calls fork and then executes shell in a child and waits for its return, that's why your updater does not exit.
See man 3 exec and man 3 system.
您将需要类似于 Windows 上的 CreateProcess 的东西来创建和运行单独的进程。
system
调用将等待您输入的任何命令完成,然后返回。You will need something along the lines of CreateProcess on Windows that creates and runs a separate process. The
system
call will wait for whatever command you entered to finish and then return.