|
Home > Archive > Unix Programming > July 2005 > PIPE buffer size unknown or ignored...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
PIPE buffer size unknown or ignored...
|
|
| Blisseth Luther 2005-07-08, 5:53 pm |
| This program should fill pipe buffer till it's full (after it must be killed
pressing ^C):
the last printf displayed should contain "ITERATION #" where # is equal to
the value of pipe buffer size.
I've read on man pages that "fpathconf(child2parent[1],_PC_PIPE_BUF)" gives
this value but I've tried to run this program and the last iteration has
# bigger than pipe buffer size:
fpathconf returns 4096 bytes but
# = 65536 on Debian, Knoppix 3.81 and 3.9 (derived from
Debian) and Ufficio Zero 0.4.2 (derived
from Arch Linux)
# = 4096 on Pentoo 2005.1 (derived from Gentoo) and
SimplyMepis 3.3.1 (derived from Debian)
Why??????
fpathconf doesn't returns pipe buffer size or it does but write writes more
than once _PC_PIPE_BUF bytes???
PLEASE REPLY ME VIA MAIL BECAUSE I CAN'T CHECK ALL THESE NEWSGROUPS.
THANKS!!!
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <limits.h>
#include <unistd.h>
inline void sys_err(char *str)
{
perror(str);
exit(1);
}
int main()
{
int child2parent[2],pid,i;
char ch='\0';
if (pipe(child2parent)<0)
sys_err("\nPipe creation error!\n");
printf("\nFather has PID %d\n",getpid());
if ((pid=fork())<0)
sys_err("\nFork error!\n");
if (pid==0)
{
close(child2parent[0]);
for (i=1;;i++)
{
if (write(child2parent[1],&ch,sizeof(ch))<=0)
sys_err("\nWrite error!\n");
if (i==_POSIX_PIPE_BUF || i==_POSIX_PIPE_BUF+1 ||
i==PIPE_BUF || i>=PIPE_BUF+1)
{
printf("\nChild has PID %d and father with ",getpid());
printf("PID %d (ITERATION %d)\n\t",getppid(),i);
printf("_POSIX_PIPE_BUF=%d\t",_POSIX_PIPE_BUF);
printf("PIPE_BUF=%d\t",PIPE_BUF);
printf("fpathconf on _PC_PIPE_BUF returns=%ld\n",\
fpathconf(child2parent[1],_PC_PIPE_BUF));
}
}
}
close(child2parent[1]);
wait(0);
return 0;
}
| |
| Rich Teer 2005-07-08, 5:53 pm |
| On Fri, 8 Jul 2005, Blisseth Luther wrote:
[Posted and emailed]
> PLEASE REPLY ME VIA MAIL BECAUSE I CAN'T CHECK ALL THESE NEWSGROUPS.
> THANKS!!!
No; you ask in a newsgroup, you read the answer there. It's just
good netiquete.
And if you cross-posted correctly (rather than multiposting), then
you'd need only check one newsgroup, as everyone's answers would
appear in all off them.
--
Rich Teer, SCNA, SCSA, OpenSolaris CAB member
President,
Rite Online Inc.
Voice: +1 (250) 979-1638
URL: http://www.rite-group.com/rich
| |
| David Schwartz 2005-07-08, 5:53 pm |
|
"Blisseth Luther" <junkmailsafe-1@yahoo.it> wrote in message
news:n1Cze.49700$h5.2082943@news3.tin.it...
> the last printf displayed should contain "ITERATION #" where # is equal to
> the value of pipe buffer size.
> I've read on man pages that "fpathconf(child2parent[1],_PC_PIPE_BUF)"
> gives
> this value but I've tried to run this program and the last iteration has
> # bigger than pipe buffer size:
Huh? Did you actually read the definition of "_PC_PIPE_BUF"? It is not
the number of bytes that a pipe can hold.
DS
|
|
|
|
|