开发者

problem with creating child processes in xcode

开发者 https://www.devze.com 2023-03-21 02:54 出处:网络
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 gettin开

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 gettin开发者_运维百科g 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


maybe you need to flush stdout, like this

printf("chicken");
fflush(stdout);


You should write something like this

pid[0]=fork();

if(pid[0]==0)
    printf("chicken");

else if (pid[0] == -1)
    perror("fork");

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号