4

I have two cooperating programs. One program just writes its output to a file and the other one then reads from the file and spits the data out for the front end to work with.

I have been reading about named pipes and domain sockets, but I am having trouble seeing what advantages they offer to just using a temp file. It just seems like a formal way of communicating to me.

0

1 Answer 1

4
  1. If you need to save the intermediate file after the processing is done, then inter-process communication (such as through a pipe or socket) is not particularly valuable.  Similarly, if you need to run the two programs at vastly different times, you should just do it the way you're doing it now.
  2. Back when Unix was created, disks were very small, and it was common for a rather benign command to consume all the free space in a file system. For example,

    some_command_that_produces_a_lot_of_output | grep some_very_obscure_string

    produces output that's much smaller than the size of the output of the first command (i.e., the size of the intermediate file that would be created if you ran the commands the way you're running your programs).

  3. Data flowing through pipes and sockets is (probably) not written to disk at all.  Therefore, these IPC solutions may be

    • more efficient (faster) than disk-based solutions.
    • more secure than disk-based solutions, if the intermediate data are more sensitive than the end result.
4
  • How are they more secure? don't you manage permissions just like you do with files?
    – Luke
    Oct 17, 2014 at 12:48
  • 1
    @LukeP - they're more secure from the standpoint that their contents are never exposed directly to the system's disks. However they're still accessible by the user that spawned them via memory (using appropriate tools to poke at the system's memory).
    – slm
    Oct 17, 2014 at 14:43
  • @LukeP - BTW IPC is covered fairly well here: tldp.org/LDP/lpg/node7.html and here: tldp.org/LDP/tlk/ipc/ipc.html. They provide you with a variety of storage mechanisms, such as semaphores, shared memory space, queues among others. I've used them in the past when I've had apps that collected data and separate apps that needed to move that data into a database. They have locking and what not and work surprisingly well.
    – slm
    Oct 17, 2014 at 14:45
  • @LukeP - most programming languages have libraries that wrap these facilities that are provided by the Kernel. search.cpan.org/~andya/IPC-ShareLite-0.17/lib/IPC/ShareLite.pm. I've used this one a fair amount.
    – slm
    Oct 17, 2014 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.