简体   繁体   English

什么更快,pipe | fifo

[英]What is faster, pipe|fifo

What is faster in linux : pipe or fifo ? 在Linux中,更快的是什么:pipe或fifo? Theoretical pipe is faster but how can i check this with a C program? 理论管道速度更快,但是如何使用C程序检查呢? I've tried to send a message between 2 procces , but the time from sending to receiving message is still 0 recklessly by lenght of message. 我尝试在2个过程之间发送消息,但是从消息长度开始,从发送到接收消息的时间仍然是0。

part of code : 部分代码:

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);

A fifo shares the same implementation as a pipe in linux, so they're equally as fast. fifo与Linux中的管道共享相同的实现,因此它们同样快。

The main difference in the two is how you create/open them. 两者的主要区别在于创建/打开它们的方式。

If you want to measure it, you'll need to do work that's measurable. 如果要对其进行度量,则需要进行可衡量的工作。 eg try to read/write 100MB of data (use a loop) . 例如,尝试读取/写入100MB的数据(使用循环)。 You also need to check for errors, since measuring how fast it takes to fail isn't what you want, and you need to check that you have actually read and written 100MB. 您还需要检查错误,因为测量失败所需的速度不是您想要的,并且您需要检查实际已读写100MB。

read() attempts to read up to count bytes from file descriptor fd into the buffer starting at buf. read()尝试从文件描述符fd读取最多计数的字节到缓冲区(从buf开始)。

this means that if you stay in the parent process you would read 0 bytes and just continue. 这意味着如果您留在父进程中,您将读取0个字节并继续。 you should notify to the parent that the reading has ended and busy wait on it. 您应该通知父母阅读已经结束,正忙于等待。 try to use signals or poll a file on the parent process and write 1 to it after the writing is done 尝试使用信号或轮询父进程上的文件,并在写入完成后向其写入1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM