在xcode中创建子进程的问题
我正在尝试在 Xcode 中编写和调试代码,在其中创建多个进程(代表网络中的节点),并且这些进程必须使用 IPC 进行通信。起初我在 msgctl 中遇到错误,我试图使用 fprintf
调试文件,当它停止创建子进程时,我在中编写了 printf
表单
pid[0]=fork();
if(pid[0]==0) {
printf("chicken");
}
但没有打印任何内容,所以我假设没有创建子进程......有人知道我应该做什么吗? 谢谢
I am trying to write and debug a code in Xcode where I create several processes (which represent nodes in a network) and where these processes have to use IPC's to communicate. at first I was getting an error in my msgctl, I was trying to debug using fprintf
to a file, when it stoped creating child processes all together, I wrote a printf
in the form
pid[0]=fork();
if(pid[0]==0) {
printf("chicken");
}
but nothing prints, so I am assuming that no child process is created... anybody know what I should do?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许你需要刷新标准输出,就像这样
maybe you need to flush stdout, like this
你应该写这样的内容,
如果 fork 不起作用,这将打印一条消息,告诉你问题出在哪里。如果它不会打印错误消息 fork 工作正常,您应该按照 neoneye 的说明刷新(stdout)。
You should write something like this
This will print a message which will tell you where the problem is if fork didn't work. If it won't print error message fork worked correctly and you should flush(stdout) as mentioned by neoneye.