POSIX: Pipe syscall in FreeBSD vs Linux
I started this as a comment on Greg's answer at first, but it occurs to me that it more closely answers your specific question:
pipe()
s documentation in the POSIX standard explicitly states that the behavior in question is "unspecified" -- that is, pipe()
is not required to be bidirectional, though it's not forbidden. Linux's is unidirectional, FreeBSD's is bidirectional. Both are compliant, one just implements additional behavior that is not required (but doesn't break apps built to work on compliant systems).
Data can be written to the file
descriptor fildes[1] and read from the
file descriptor fildes[0]. A read on
the file descriptor fildes[0] shall
access data written to the file
descriptor fildes[1] on a
first-in-first-out basis. It is
unspecified whether fildes[0] is also
open for writing and whether fildes[1]
is also open for reading.
I wouldn't count on getting the points back (though you should). Professors have a tendency to ignore the real world in favor of whatever they've decided is correct.
POSIX `pipe` both ways
Pipes are strictly unidirectional. But in a POSIX environment you may have access to the 'socketpair()' call which, when used with 'AF_UNIX" socket domain will give you a pair of bidirectional descriptors all connected and ready to go. This is handy if you will fork and the descriptors get inherited. If you are trying to connect two separate pre-existing processes, then you will need to create the sockets manually and use the sockets calls to connect them.
-pipe flag of cc on FreeBSD 10.x
I sent an Email to Salvatore Sanfilippo (author of Redis) and asked above question and he replied with:
Hello, it simply will use Unix pipes instead of files in order to
"chain" the different stages needed for the compilation process. When
-pipe is used, as GCC starts to emit the assembler code, the assembler
will start to read from the pipe and emit the machine code and so
forth. It should optimize compilation speed, but in practice it helps
very little AFAIK.
Thanks to him.
-pipe flag of cc on FreeBSD 10.x
I sent an Email to Salvatore Sanfilippo (author of Redis) and asked above question and he replied with:
Hello, it simply will use Unix pipes instead of files in order to
"chain" the different stages needed for the compilation process. When
-pipe is used, as GCC starts to emit the assembler code, the assembler
will start to read from the pipe and emit the machine code and so
forth. It should optimize compilation speed, but in practice it helps
very little AFAIK.
Thanks to him.
POSIX named pipe (fifo) drops record in nonblocking mode
You have multiple writers using one FIFO sending messages of 720 bytes. POSIX only requires writes of PIPE_BUF
(512 bytes, normally) to be atomic. That means that longer writes can get interleaved by writes from other threads and get corrupted.
Regardless of PIPE_BUF
size, pipes are streams and they don't have a notion of a message, and that means you need to delimit messages yourself, which your code doesn't do. In other words, your reader code cannot possibly recover the individual messages when there are multiple writers.
You may like to use a Unix datagram socket instead. Each message into a Unix datagram socket is an atomic message and it gets written and read completely in one syscall (sendto
and recvfrom
).
FreeBSD POSIX C Oracle API
Oracle themselves do not support FreeBSD. There are ports of their Linux client-libraries, however, that are made to work on the OS:
- databases/oracle8-client
- databases/oracle7-client
Unfortunately, the above two are currently only working on i386, but you may be able to use the same technique as the port's author to massage the x86_64 Linux binaries to work under FreeBSD/amd64.
And then there is a port of the open-source ODBC driver in:
- databases/oracle_odbc_driver
This one requires oracle8-client and is thus also i386-only at this time.
Linux newbie: Linux vs POSIX manual
Basically, the linux manuals are documentation of the commands/APIs from their writers; The POSIX manuals are from the POSIX standard. Usually, the "normal" ones are shorter and terser, but deal with the specific implementation; the POSIX ones are longer and more detailed (see man 3p read
), but only tell what is in the standard.
The best is to look in both.
Best way to port C++ code that uses a bidirectional popen() to POSIX
socketpair(2) creates a pair of sockets that are endpoints of a bidirectional pipe. This will directly replace popen()
. I do not see why CMD
being or not being an interactive program has anything to do with it.
It is possible that the program might need to have an actual terminal device (unlikely, since popen
() doesn't really emulate one). If so, the pty(7) man page provides additional documentation for creating a bi-directional pipe that drives a pseudo-tty device.
Related Topics
Find String Inside PDF with Shell
Find Port Number of Ibm Mq Queue Manager
How to Source a Simple Bash Script
Implementation of Function Execve (Unistd.H)
Linux Kill Process Using Timeout in Milliseconds
Errors While Trying to Build Gdb for Arm
Case Statement in a While Loop, Shell Scripting
./Configure-With-Boost No Such File or Directory
Finding All Directories That Are World Readable
Linux Allocates Memory at Specific Physical Address
Kaldi Toolkit Installation Error on Ubuntu 16.04
What Does "Warning: Not Changing User" Mean in Neo4J
How to Read a Value from User Input into a Variable
How to Add a Ppa Repository Using Ansible
/Usr/Bin/Ld: Cannot Find -Lglut
Error While Using Make to Compile Glibc-2.11.1 for Linux from Scratch
Libnetfilter_Queue Programming, How to Know Which Program Send The Packet