gpt4 book ai didi

c - 我如何使用 vfork 在 uClinux 中生成守护进程?

转载 作者:可可西里 更新时间:2023-11-01 11:44:46 26 4
gpt4 key购买 nike

使用 fork() 会很容易,但我没有 MMU。我听说 vfork() 会阻塞父进程,直到子进程退出或执行 exec()。我将如何完成这样的事情?:

pid_t pid = vfork();

if (pid == -1) {
// fail
exit(-1);
}

if (pid == 0) {
// child
while(1) {
// Do my daemon stuff
}

// Let's pretend it exits sometime
exit();
}

// Continue execution in parent without blocking.....

最佳答案

似乎没有办法完全按照您在这里的方式执行此操作。必须调用 exec_exit 才能让父级继续执行。要么将守护程序代码放入另一个可执行文件并exec,要么使用子进程生成原始任务。第二种方法是偷偷摸摸的方法,在此处进行了描述。

关于c - 我如何使用 vfork 在 uClinux 中生成守护进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3893293/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com