【发布时间】:2014-10-21 11:52:07
【问题描述】:
Linux 中哪个更快:管道还是 fifo?理论上的管道更快,但我如何用 C 程序检查呢? 我尝试在 2 个 procces 之间发送消息,但是从发送到接收消息的时间仍然是 0 鲁莽的消息长度。
部分代码:
struct timeval start,end;
char mesaj[100000]="";
for(i=0;i<99999;i++)
strcat(mesaj,"d");
gettimeofday(&start,NULL);
if(fork()==0)
{
write(fd,mesaj,strlen(mesaj));
exit(0);
}
read(fd,mesaj,strlen(mesaj));
gettimeofday(&end,NULL);
long time=(end.tv_usec-start.tv_usec)/1000 + (end.tv_sce-start.tv_sec)*1000;
printf("Fifo time &lu\n",time);
【问题讨论】:
-
尝试发送1,000,000,看看哪个更快
-
您的标签将苹果与橙子进行比较。 unix
pipe是一个实用的东西,而fifo是一个概念。你到底在比较什么? -
在这部分代码中,我想使用 fifo 获取时间,我有使用管道获取时间的方法,是一样的,但是 fd 是 int fd[2],我之前启动了管道叉子。