You cannot simply exec a binary from a pipe: Is there a way to execute a native binary from a pipe?. Also I don't think the sticky bit on executables is worth anything on modern systems.
I created the pipe in the server code with mkfifo("fifo",1755);
I went to see the permissions of the pipe fifo and it says p-wx--s--t so:
Your error is to have ...
APUE says “FIFOs can be used to duplicate an output stream”, it doesn’t say that FIFOs actually duplicate the output stream. As you point out, the duplication is done by tee in the example.
mkfifo creates a FIFO, which is visible as a “file” in the containing directory; but writing to the FIFO isn’t like writing to a file because the data never hits the disk....
Such a command is taking advantage of IO redirection and and sh interactive mode which is on by default when attached to a TTY.
Note that cat stays open on a FIFO. Thats your first clue. When sh runs all its ever doing is directing its stdout and strerr to the TTY. Instead sh is not attached to a TTY. Normally sh automatically goes into interactive mode ...
It sounds like you're looking for some variant of named pipes (fifos) created with mkfifo.
Then you can do something like this:
node script.js < my-pipe &
Note that will block until something opens my-pipe for writing. So if you want script.js to be able to open the file (but not of course read anything from it yet), then you need ...
You need to use the -p construct to see if the file is of type named pipe. It works with the standard test [ (POSIX compliant) and the extended test operators [[ ( bash/zsh specific )
if [[ -p "$fifo" ]]; then
printf '%s is a named pipe' "$fifo"
From the man pages of bash
True if file exists and is a named pipe (FIFO).
or use the ...
You can't use mkfifo to copy or move files, no. mkfifo creates a named pipe. You can use a pipe to arrange for data to go to a different place, and occasionally a named pipe is the only way or is more convenient. You can find some solutions that use mkfifo on this site. But a pipe isn't usually useful if you only want data to end up in a different place: for ...
On (at least) Linux-based systems a FIFO or Named Pipe is unidirectional. In your situation you want to have a program reading and writing to the same FIFO. This gets even more tricky because you may well up with a deadlock if you exceed the pipe's internal buffer.
Two general points.
You cannot usefully have two readers; if you do, you'll find that your ...
Process substitution doesn’t necessarily involved named pipes; it can be implemented using /dev/fd on platforms which support that.
At least with Bash on Linux, process substitution is significantly faster than FIFOs. Based on Performance differences between pipelines and process substitution, I used the following script to test FIFOs:
for i in ...
cat $F | tee -a >( read B; echo "B=$B" >&2 ) >( read C; echo "C=$C" >&2 ) | (read A; echo "A=$A") &
echo OK > $F
">()" is process substitution
internal tee workings here.
Note that all 3 outputs are run at the same time (test by adding sleep 1;), if you want to wait for A ...
Recommended way is like this:
Example for your modifying program yours.c (doesn't do anything):
int main (int argc, char argv)
n = fread(buf, sizeof(char), sizeof(buf), stdin);
fwrite (buf, sizeof(char), n, stdout);
} while (n > 0);
Setup for the original program: