为什么不等到孩子终止?

为什么不等到孩子终止?,第1张

概述为什么不等到孩子终止

voID *stack; stack = malloc(STACK_SIZE); if (-1 == clone(child_thread,stack + STACK_SIZE,NulL)) { perror("clone Failed:"); } while(waitID(P_ALL,NulL,WEXITED) != 0){ perror("waitID Failed:"); sleep(1); }

手册说:

如果一个孩子已经改变了状态,那么这些调用立即返回。 否则,他们阻止,直到一个孩子改变状态

但实际上它立即返回:

waitID Failed:: No child processes waitID Failed:: No child processes ...

有什么build议?

在windows上使用Hudson的Git插件克隆/获取存储库问题

clone()函数隐式声明

CLONE_VM未申报(首次在此function中使用)

git克隆错误:RPC失败; curl 56 OpenSSL SSL_read:SSL_ERROR_SYSCALL,errno 10054

不要运行一个cron PHP任务,直到最后一个完成

如何在Ubuntu *** 作系统上使用cron作业每日运行一个PHP脚本

clone()系统调用是否最终依赖于fork函数?

Mercurial hg克隆错误 – “中止:错误:名称或服务未知”

linux – 理解挂载名称空间和克隆CLONE_NEWNS标志

什么时候clone()和fork比pthread更好?

您正在使用PID选项。 进一步查看手册页:

以下linux专用选项用于使用clone(2)创建的子项; 它们不能用于waitID():

__WCLONE Wait for "clone" children only. If omitted then wait for "non- clone" children only. (A "clone" child is one which delivers no signal,or a signal other than SIGCHLD to its parent upon termi- nation.) This option is ignored if __WALL is also specifIEd. __WALL (Since linux 2.4) Wait for all children,regardless of type ("clone" or "non-clone"). __WNOTHREAD (Since linux 2.4) Do not wait for children of other threads in the same thread group. This was the default before linux 2.4.

我不知道你想在这里做什么的具体细节,但通过以下方式使用waitID可能会有所帮助:

#include <sys/types.h> #include <sys/wait.h> ... siginfo_t signalinfo; waitID(P_ALL,&signalinfo,WEXITED | WStopPED | WNowAIT | WNOHANG);

然后在signalinfo中检查以下内容,以便知道小孩什么时候退出:

signalinfo.si_signo : For Signal Number signalinfo.si_code : Usually SIGCHLD signalinfo.si_errno) : Any error code set signalinfo.si_status : For exit code of the child code

注意:使用WNowAIT可以使 *** 作系统保留子进程资源的使用情况,即使它被终止。 您可能/不可以使用此选项。 如果你这样做了,你将不得不在WNowAIT选项中显式调用waitID。

参考:请参阅manID页面了解更多关于此的信息。

总结

以上是内存溢出为你收集整理的为什么不等到孩子终止?全部内容,希望文章能够帮你解决为什么不等到孩子终止?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1158510.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存