开发者

c++ launch new process and terminate existing one

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?


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.


Look into CreateProcess on Windows or exec on Unix. Use macros to create a wrapper over the OS specific code.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜