sizeof PIPE_BUF
Nikola Vladov <[email protected]>
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Message-ID | <[email protected]> |
Hi!
How big is actally PIPE_BUF? Seems that on 2.6 kernels it is 64K
and on 2.4 is 4K. Or I make a mistake? The program bellow show
this. The result is the same with glibc, or dietlibc.
=============
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
int ndelay_on(int fd) {
return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) | O_NONBLOCK);
}
void wr_number(unsigned long u) {
char buf[64], *p, *e;
e = p = buf + sizeof(buf);
*--p = '\n';
do { *--p = '0' + u%10; u /= 10; } while (u);
write(1, "#define MAX_PIPE_length ", 24);
write(1, p, e-p);
}
int main() {
int r, pi[2];
pid_t pid;
if (pipe(pi)) return 21;
if (ndelay_on(pi[1])) return 22;
pid = fork();
if (pid==-1) return 23;
if (pid==0) {
char buf[1024];
unsigned long total=0;
close(pi[0]);
while (1) {
r = write(pi[1], buf, sizeof(buf));
if (r <= 0) break;
total += r;
}
wr_number(total);
} else {
close(pi[1]);
waitpid(pid, 0, 0);
}
_exit(0);
return 0;
}