Post subject: UNIX users wanted for "pipe" survey
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
If you use or have access to different flavors of FreeBSD, DragonFlyBSD, NetBSD, OpenBSD, Mac OS X, Solaris, or some modern UNIX, I'd appreciate your help. Some information is sorely lacking in documentation regarding pipe implementation details (except for in Linux), and I'd like to conduct a survey with your help. Please download, compile, and run the following code: Download pipesize.c
Language: c

#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/utsname.h> #include <errno.h> #include <limits.h> void output_system_id() { struct utsname n; if (!uname(&n)) { char *p = n.release; unsigned long major, minor, patch; major = minor = patch = 0; major = strtoul(p, &p, 10); if (*p == '.') { minor = strtoul(p+1, &p, 10); if (*p == '.') { patch = strtoul(p+1, &p, 10); } } printf("%s %lu.%lu.%lu %s\n", n.sysname, major, minor, patch, n.machine); } } int main() { union { int pipefd[2]; struct { int read; int write; } command; } u; output_system_id(); printf("PIPE_BUF size: %d\nPipe size: ", PIPE_BUF); fflush(stdout); if (!pipe(u.pipefd)) { int flags = fcntl(u.command.write, F_GETFL, 0); if (flags != -1) { if (fcntl(u.command.write, F_SETFL, flags | O_NONBLOCK) != -1) { size_t amount; for (amount = 0;; amount += sizeof(size_t)) { ssize_t w = write(u.command.write, &amount, sizeof(size_t)); if (w != sizeof(size_t)) { if (w == -1) { if (errno == EINTR) { amount -= sizeof(size_t); } else { if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { printf("%zu\n", amount); } else { perror("Failed to write to pipe"); } break; } } else if (!w) { perror("Pipe unexpectedly closed"); break; } else { amount -= sizeof(size_t); amount += w; } } } } else { perror("Failed to set pipe nonblocking"); } } else { perror("Failed to get pipe flags"); } close(u.command.read); close(u.command.write); } else { perror("Failed to create pipe"); } return(0); }
Example of how to compile and run:
/tmp> gcc -Wall -o pipesize pipesize.c
/tmp> ./pipesize
Linux 2.6.32 x86_64
PIPE_BUF size: 4096
Pipe size: 65536
/tmp>
Please post your output here. Thanks.
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Linux 2.6.35 x86_64 PIPE_BUF size: 4096 Pipe size: 65536 CYGWIN_NT-5.1 1.7.9 i686 PIPE_BUF size: 4096 Pipe size: 65540 Linux 2.6.32 i686 PIPE_BUF size: 4096 Pipe size: 65536 Linux 2.6.27 x86_64 PIPE_BUF size: 4096 Pipe size: 65536 Linux 2.2.26 i686 PIPE_BUF size: 4096 Pipe size: 4096 Linux 2.4.25 i686 PIPE_BUF size: 4096 Pipe size: 4096 Enough?
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
Bisqwit wrote:
CYGWIN_NT-5.1 1.7.9 i686 PIPE_BUF size: 4096 Pipe size: 65540
I'm quite surprised by that last size... Probably have a bug in my code?
Bisqwit wrote:
Enough?
For Linux yes, Linux is well documented. "man 7 pipe".
   Pipe Capacity
       A pipe has a limited capacity.  If the pipe is full, then a write(2) will block or fail, depending on whether the
       O_NONBLOCK  flag  is  set  (see  below).   Different implementations have different limits for the pipe capacity.
       Applications should not rely on a particular capacity: an application  should  be  designed  so  that  a  reading
       process consumes data as soon as it is available, so that a writing process does not remain blocked.

       In Linux versions before 2.6.11, the capacity of a pipe was the same as the system page size (e.g., 4096 bytes on
       i386).  Since Linux 2.6.11, the pipe capacity is 65536 bytes.
   PIPE_BUF
       POSIX.1-2001 says that write(2)s of less than PIPE_BUF bytes must be atomic: the output data is  written  to  the
       pipe  as  a  contiguous sequence.  Writes of more than PIPE_BUF bytes may be nonatomic: the kernel may interleave
       the data with data written by other processes.  POSIX.1-2001 requires PIPE_BUF to be at  least  512  bytes.   (On
       Linux,  PIPE_BUF  is  4096  bytes.)
The standard is also documented well. Unfortunately the man pages of other UNIXes out there contain little or no information on their implementation details. So I still want this survey for those to continue. Thanks for posting Cygwin! :)
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
Joined: 7/2/2007
Posts: 3960
OSX 10.5.8: Darwin 9.8.0 i386 PIPE_BUF size: 512 Pipe size: 16384
Pyrel - an open-source rewrite of the Angband roguelike game in Python.
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Bisqwit wrote:
CYGWIN_NT-5.1 1.7.9 i686 PIPE_BUF size: 4096 Pipe size: 65540
Also: CYGWIN_NT-6.1-WOW64 1.7.7 i686 PIPE_BUF size: 4096 Pipe size: 65540
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
Thanks guys, this is helpful. Bisqwit: Cygwin not being a power of 2 scares me... Is something wrong somewhere? I noticed though that recent Cygwin (and recent Linux) has a more direct way of getting the pipe size. Can you try this for me please? Download pipesize2.c
Language: c

/* Linux 2.6.35+ and recent Cygwin only */ #define _GNU_SOURCE /* Raaaaaaaaaaaaaaaaaaaaaaaaaaaaa */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/utsname.h> #include <errno.h> #include <limits.h> void output_system_id() { struct utsname n; if (!uname(&n)) { char *p = n.release; unsigned long major, minor, patch; major = minor = patch = 0; major = strtoul(p, &p, 10); if (*p == '.') { minor = strtoul(p+1, &p, 10); if (*p == '.') { patch = strtoul(p+1, &p, 10); } } printf("%s %lu.%lu.%lu %s\n", n.sysname, major, minor, patch, n.machine); } } int main() { int pipefd[2]; output_system_id(); printf("PIPE_BUF size: %d\nPipe size: ", PIPE_BUF); fflush(stdout); if (!pipe(pipefd)) { int size = fcntl(*pipefd, F_GETPIPE_SZ, 0); if (size != -1) { printf("%d\n", size); } else { perror("Failed to get pipe size"); } close(pipefd[0]); close(pipefd[1]); } else { perror("Failed to create pipe"); } return(0); }
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
Player (121)
Joined: 2/11/2007
Posts: 1522
Not that it counts as a modern unix, but for shits and giggles: AIX 3.0.0 0003183A4C00 PIPE_BUF size: 32768 Pipe size: 32768 Apparently this version is from 1989? wtf work way to keep up with the joneses
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
Thanks Alden, and cool architecture you got there.
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
Experienced player (545)
Joined: 5/12/2005
Posts: 707
Here's mine: Linux 2.6.38 x86_64 PIPE_BUF size: 4096 Pipe size: 65536
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Nach wrote:
I noticed though that recent Cygwin (and recent Linux) has a more direct way of getting the pipe size. Can you try this for me please?
It does not compile in my Cygwin installation (which I just upgraded). F_GETPIPE_SZ undeclared. EDIT: Shinryuu's avatar O_o
Player (121)
Joined: 2/11/2007
Posts: 1522
Nach wrote:
Thanks Alden, and cool architecture you got there.
Oh, haha, I didn't even notice that. It's theoretically some IBM PowerPC something or other, I guess?
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
Thanks Shinryuu.
Bisqwit wrote:
Nach wrote:
I noticed though that recent Cygwin (and recent Linux) has a more direct way of getting the pipe size. Can you try this for me please?
It does not compile in my Cygwin installation (which I just upgraded). F_GETPIPE_SZ undeclared.
Odd... Google Search: site:cygwin.com F_GETPIPE_SZ
alden wrote:
Nach wrote:
Thanks Alden, and cool architecture you got there.
Oh, haha, I didn't even notice that. It's theoretically some IBM PowerPC something or other, I guess?
No idea, Google says nothing on that serial number.
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
Player (121)
Joined: 2/11/2007
Posts: 1522
Apparently it is actually this (!): http://en.wikipedia.org/wiki/Common_Hardware_Reference_Platform FASCINATING I KNOW
I make a comic with no image files and you should read it. While there is a lower class, I am in it, and while there is a criminal element I am of it, and while there is a soul in prison, I am not free. -Eugene Debs
Post subject: Modified Version
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
If anyone for some reason found the source code here interesting, there's an improved version of some of it here: http://insanecoding.blogspot.com/2012/07/creating-portable-linux-binaries.html
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.
WST
She/Her
Active player (490)
Joined: 10/6/2011
Posts: 1697
Location: RU · ID · AM
Do you still need it?
Linux 3.4.4 i686
PIPE_BUF size: 4096
Pipe size: 65536
S3&A [Amy amy%] improvement (with Evil_3D & kaan55) — currently in SPZ2 my TAS channel · If I ever come into your dream, I’ll be riding an eggship :)
Emulator Coder
Joined: 3/9/2004
Posts: 4588
Location: In his lab studying psychology to find new ways to torture TASers and forumers
WST wrote:
Do you still need it?
Linux 3.4.4 i686
PIPE_BUF size: 4096
Pipe size: 65536
I got the info I wanted, thanks.
Warning: Opinions expressed by Nach or others in this post do not necessarily reflect the views, opinions, or position of Nach himself on the matter(s) being discussed therein.