Think about Loose Coupling | |
PerlMonks |
Re: What is a pipe and why would I want to use one?by Zaxo (Archbishop) |
on Jul 10, 2002 at 05:27 UTC ( [id://180683]=note: print w/replies, xml ) | Need Help?? |
A pipe is a method of Interprocess Communication (IPC). It supports moving data from one process to another by creating a pair of filehandles, one write-only, one read-only. The pipe must be created before fork so that the filehandles are known to both processes. The writer process closes the read-only handle, the reader closes the write handle. At that point, the writer prints whatever it has to communicate to the write handle, and the reader will find the data on the read handle. I've seen plenty of good examples here, but here is one that does so little that the main features are easy to see: We close $out in the parent so that the child's print loop ends, and it exits. The parent waits for the child's exit so as to clean up afterwords. There are lots of other ways of doing multiprocess programming and IPC. There is a form of the open function which takes care of the details for you. I'd recommend Advanced Programming in the UNIX Environment for a good explanation of processes and ipc generally. perlipc is a concentrated course in using perl's process and ipc functions together. After Compline,
In Section
Seekers of Perl Wisdom
|
|