【发布时间】:2015-02-18 08:58:02
【问题描述】:
我正在编写一个程序来测量执行进程切换所需的时间。为了做到这一点,我让父母给它的孩子写一个字节的消息,然后孩子读它。
我的问题在这个循环中:
for(i=0; i<2; i++)
{
if(fork()==0) //child process, read
{
close(pipefd[1]);
read(pipefd[0]);
close(pipefd[0]);
}
else //parent process
{
close(pipefd[0]);
write(pipefd[1]);
close(pipefd[0]);
}
}
为了测试叉子撞击父子节点的频率,我输入了一个 printf 语句,我在屏幕上打印了大约 15 个语句。考虑到循环应该只运行两次,这怎么可能?
【问题讨论】:
标签: c operating-system