Hot answers tagged

13

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 ...


5

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....


4

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 ...


4

It sounds like you're looking for some variant of named pipes (fifos) created with mkfifo. Then you can do something like this: mkfifo my-pipe 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 ...


3

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" fi From the man pages of bash -p file True if file exists and is a named pipe (FIFO). or use the ...


3

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 ...


3

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 ...


2

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: mkfifo fifo for i in ...


2

tail only outputs the last n lines of a file/stream. While you are still generating lines, it can not know which are the last n. Have you tried something like cat?


1

F=example.fifo mkfifo $F cat $F | tee -a >( read B; echo "B=$B" >&2 ) >( read C; echo "C=$C" >&2 ) | (read A; echo "A=$A") & echo OK > $F A=OK B=OK C=OK rm $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 ...


1

Recommended way is like this: Example for your modifying program yours.c (doesn't do anything): #include <stdio.h> int main (int argc, char argv[]) { char buf[1024]; int n; do { n = fread(buf, sizeof(char), sizeof(buf), stdin); fwrite (buf, sizeof(char), n, stdout); } while (n > 0); } Setup for the original program: mknod first....


1

Experimentally, in bash: $ strace -tttfe execve bash -c 'sleep 5 <(sleep 6)' 1522025733.188859 execve("/bin/bash", ["bash", "-c", "sleep 5 <(sleep 6)"], [/* 41 vars */]) = 0 strace: Process 24248 attached [pid 24247] 1522025733.215188 execve("/bin/sleep", ["sleep", "5", "/dev/fd/63"], [/* 41 vars */]) = 0 strace: Process 24249 attached [pid 24249] ...


Only top voted, non community-wiki answers of a minimum length are eligible