2

I have a program that creates a FIFO (named pipe) file in /path/to/directory, then deletes it. I have somehow managed to stop it being deleted, but still I can't read/write/copy anything on it.

For example;

$ cp 15796 test

It just keeps waiting, then exits itself (I think).

If I'm quick enough, I can get partial data out of this pipe. Is there a way to copy all data sent through this pipe?

wizzwizz4
  • 129
  • 8
Erikli
  • 429
  • 2
  • 6
  • 11
  • What do you want to do with it? If nothing is writing to the FiFo, there is nothing to read from it. If something has written to it, you should be able to just cat fifo and see it. – terdon Sep 08 '22 at 16:32
  • There is a binary file which creates it. It has his source on it. I want to read it but I cant. – Erikli Sep 08 '22 at 16:34
  • Did you try what I said? – terdon Sep 08 '22 at 16:34
  • Yes, I have added it on the question. – Erikli Sep 08 '22 at 16:35
  • 1
    @terdon As per the linked question: this fifo is written to and read by existing processes. OP wants to intercept and read the data from it, without breaking that system. – wizzwizz4 Sep 08 '22 at 16:43
  • Does the fifo ave a standard name? Can you create it before launching the program, start reading from it (cat < fifo > someOtherFile) before launching the program, and then launch the program and have it write to the existing fifo? – terdon Sep 09 '22 at 10:00
  • @terdon No, I can't create it before launching the program. It doesn't write to the existing fifo because all fifo's name are different. For example I'm launching the program, the program creates fifo named as 5610, then I launch it again and it creates another fifo named as 7410. I guess It takes his name from pid. – Erikli Sep 09 '22 at 12:13
  • I don't have time to post a full answer, but one thing to try would be to use inotifywait to detect the creation of the file or, if it is indeed the PID, run something like while :; do pid=$(pgrep -f programName); if [ -n "$pid" ]; then cat < /path/to/directory/"$pid"; fi; done to read from it. You will still have a race condition, but should get something at least. – terdon Sep 09 '22 at 16:55

0 Answers0