作者:BigUncle | 来源:互联网 | 2023-05-18 16:20
I have the following code:
我有以下代码:
for(i=0; i 0)
{
close(fd[1]);
// read the string, and print it
}
else if (pid == 0)
{
close(fd[0]);
// write the file name to the main process
break;
}
}
// wait for all processes to finish
So basically, it outputs each file name in sequential order:
所以基本上,它按顺序输出每个文件名:
file1
file2
file3
But if I put printf("%d\n", getpid())
after the for loop, the outputs seems concurrent. Some processes with a higher process id are printed first.
但是如果我在for循环之后放置printf(“%d \ n”,getpid()),输出似乎是并发的。首先打印一些具有更高进程ID的进程。
My question is, the way I do the pipe read/write inside the for loop, is it sequential or concurrent?
我的问题是,我在for循环中进行管道读/写的方式是顺序还是并发?
2 个解决方案