Linux CreateProcess? [英] Linux CreateProcess?
问题描述
我在linux平台上开发。
我想在我的库中创建一个新的进程,而不替换当前执行的映像。
因为我正在开发一个库,我没有主函数。
我想在调用者应用程序后继续新的进程关闭(就像CreateProcess Windows API)。
在Linux中是否可能?
函数:
void Linux_CreateProcess(const char * app_name)
{
//执行app_name。
//什么是代码?
// app_name正在运行,如果当前应用程序关闭,则不会关闭。
return;
}
注意:
-
system()阻塞当前进程,这不好。我想继续当前的过程。
-
exec()家庭替换当前执行的图像,不好。
$ b
fork()
,然后 exec()
使用 fork()
(或 vfork()
)启动单独的进程,这将是父的克隆。在子进程和父进程中,执行都继续,但 fork
在两种情况下返回不同的值,允许您区分。然后,您可以在子进程中使用 exec()
。
您还可以阅读我的一个博文:
http://davmac.wordpress.com/2008/ 11/25 / forkexec-is-forked-up /
I develop on the linux platform.
I want to create a new proccess in my library without replacing the current executing image.
Because I am developing a library, I don't have a main function.
And I want to continue the new process after the invoker application closes (Just like CreateProcess Windows API).
Is it possible in Linux or not?
something like this function:
void Linux_CreateProcess(const char* app_name)
{
// Executing app_name.
// ???????? what is the code ??????
// app_name is running and never close if current application close.
return;
}
Note:
system() blocks the current process, it is not good. I want to continue current process.
exec() family replace the current executing image, it is not good.
popen() closes the new process if current process closed.
fork()
and then exec()
is the standard solution.
Use fork()
(or vfork()
) to launch a separate process, which will be a clone of the parent. In both the child and parent process, execution continues, but fork
returns a different value in either case allowing you to differentiate. You can then use exec()
from within the child process.
You may also wish to read one of my blog posts: http://davmac.wordpress.com/2008/11/25/forkexec-is-forked-up/
这篇关于Linux CreateProcess?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!