非阻塞系统调用在c ++程序中使用fork [英] non-blocking system call in c++ program using fork

查看:274
本文介绍了非阻塞系统调用在c ++程序中使用fork的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此SO 帖子,此示例,我期望,当我使用fork(),将允许我以非阻塞的方式执行system / execvp。然而,当我尝试在上面提到的示例代码中的fork块中发出长时间运行的子进程时,控件不会返回父块,直到子进程结束。



你可以告诉一个方法,我应该如何设计代码以允许对C / C ++代码的非阻塞调用。此外,我打算写一个程序,其中多个chidren是从同一个父母分叉。

解决方案



感谢您的帮助。 / div>

fork 将立即返回到子节点和父节点。但是,该示例(test3.c)调用 wait4 ,这听起来像是等待另一个进程做某事(在这种情况下退出)。


Based on this SO post, and this example, I expect that, when I use fork(), will allow me executing system/execvp in non-blocking manner. However, when I try to issue a long-running child process in a fork block in the above mentioned example code, the control does not return to parent block, till the child has finished.

Can you tell a method, how I should design the code to allow non-blocking calls to system, in C/C++ code. Also, I plan to write a program, where more than one chidren are forked from a same parent. How can I get the pid of the children?

Thanks for your kind help.

解决方案

fork will immediately return to both the child and parent. However, that example (test3.c) calls wait4, which like it sounds, waits for another process to do something (in this case exit).

这篇关于非阻塞系统调用在c ++程序中使用fork的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆