in reply to while reading a file, transfer the same data to two different processes.

Why fork? What's wrong with:
while ($record = $fp->getline()) { function1($record); function2($record); }
  • Comment on Re: while reading a file, transfer the same data to two different processes.
  • Download Code

Replies are listed 'Best First'.
Re^2: while reading a file, transfer the same data to two different processes.
by avanta (Beadle) on May 20, 2010 at 15:49 UTC
    I need to "fork" because I dont want any interference of the two functions. i.e. if "function1" crashes it should not affect "funtion2". To put it this way, my "function1" is in the current script from where I am running the process and "function2" is collection of different procesing steps which may be huge so if "function1" dies due to some reason the whole process will crash and "function2" will die along with it, and I dont wish to have a scene like this. I wish to have "function2" continue.
      But the other way is fine? That is, function1 may crash and take with it the entire process?

      What you could do is for each line, fork twice. First child calls function1, second child calls function2. Both children exit afterwards. Parent waits till children are done before reading the next batch. Then the process will not be stopped if either function crashes on a batch.

        But here "function1" and "function2" are not processing just for every record. they are processing first record and then join the results to second record after processing and so on...so in short i cannot kill the process while returning to start of the loop.