#include<iostream>
#include<sys/types.h>
#include<unistd.h>
#include<fcntl.h>
using namespace std;
int main()
{
int fd[2];
int pipefd = pipe(fd);
fcntl(fd[1], F_SETFL, fcntl(fd[1], F_GETFL)|O_NONBLOCK);
int count = 0;
int ret;
for(;;)
{
ret = write(fd[1], "", 1);
if(ret==-1 || ret == 0)
break;
count++;
}
cout<<count<<endl;
char buf[100000];
cout<<read(fd[0], buf, 100000)<<endl;
}
结果:
tony@ubuntu:~/test$ ./pipe
65536
65536
实际证明在我的64位ubuntu上pipe的实际大小是65536