creeble has asked for the wisdom of the Perl Monks concerning the following question:

Ug, I've got a mental block on this. I have one process that occasionally prints out a few lines of stuff. I have another process that needs to check to see if there's stuff to read (non-blocking), and read all the lines the first process printed (since the last read). What's the best way to do this? UNIX-domain sockets? How does the output of process 1 get buffered? Oof!
  • Comment on One writer, one reader, FIFO? Unix domain socket?

Replies are listed 'Best First'.
Re: One writer, one reader, FIFO? Unix domain socket?
by ikegami (Patriarch) on Feb 05, 2010 at 07:10 UTC

    There's really not that much difference between the different communication channels. The differences are mostly in what can connect the communication channel. Internet sockets give the most flexibility and the least security without addition code. (At best, you can accept connections only from the local machine.) An anon pipe between parent and child provides the most security, but the least flexibility. (You'd have to your application a bit if you decided to move one of the processes to another machine.)

    What are your needs? Is there a parent-child relationship between the two processes?

    How does the output of process 1 get buffered?

    Since you're asking what method to use to communicate, I presume you have control over he code of both apps. If so, you are free to disable buffering (or not) no matter what channel you use.

Re: One writer, one reader, FIFO? Unix domain socket?
by JavaFan (Canon) on Feb 05, 2010 at 07:05 UTC
    What's the best way to do this?
    That depends. I might go for (regular) pipes and a select loop, but your problem description does not have enough information to tell for sure. Pipes will not work if not both processes run at the same time.
Re: One writer, one reader, FIFO? Unix domain socket?
by ikegami (Patriarch) on Feb 05, 2010 at 07:13 UTC
    [ Duplicate post, please ignore ]

    There's really not that much difference between the different communication channels. The differences are mostly in what can connect the communication channel. Internet sockets give the most flexibility and the least security without addition code. (At best, you can accept connections only from the local machine.) An anon pipe between parent and child provides the most security, but the least flexibility. (You'd have to your application a bit if you decided to move one of the processes to another machine.)

    What are your needs? Is there a parent-child relationship between the two processes?

    How does the output of process 1 get buffered?

    Since you're asking what method to use to communicate, I presume you have control over he code of both apps. If so, you are free to disable buffering (or not) no matter what channel you use.