fork()的奇怪输出结果,急求高手解答
我在fedora12写了这样一段程序,
运行结果却很奇怪,为:
$ ./ex2_1.out
before fork: pid = 2483, ppid = 2331
We are in Child Process, child ID = 2484, parent ID = 2483
Processes have finished! pid = 2484, ppid = 2483
We are in Child Process, child ID = 2483, parent ID = 2331
Processes have finished! pid = 2483, ppid = 2331
为什么两次都进入了子进程阿, 而且这也说不通,fork之前的进程ID应该是父进程的,但是为什么没有进入pid > 0这个条件,而是也进入了pid == 0这个条件了,我学 linux 编程不久,被这个问题困惑了很久,那位牛人能知道,帮解答下?
[解决办法]
看不到你的程序啊。
[解决办法]
if((pid = fork()) < 0)