in reply to Cannot print child process command during fork

Forking child process, only to run a brief system command seems pointless, because system already does a fork.

To answer your question, simultanious writing to the same file handle by so many child processes probably gets them to clobber each other occasionally.

I would recommend getting rid of the fork entirely - simply put 24 system calls in a loop.

     "An undefined problem has an infinite number of solutions." - Robert A. Humphrey         "If you're not part of the solution, you're part of the precipitate." - Henry J. Tillman

  • Comment on Re: Cannot print child process command during fork

Replies are listed 'Best First'.
Re^2: Cannot print child process command during fork
by BrowserUk (Patriarch) on Aug 02, 2007 at 05:31 UTC
      Since no useful work appears to be done at the conclusion of the forked child processes, and $proc and $cmd were unspecified, I assumed that $cmd was a brief command that started a remote process, and exited. If this is the case, the difference between serial and parallel processing would not be significant.

      So, point taken. I should have clarified my assumptions.

           "An undefined problem has an infinite number of solutions." - Robert A. Humphrey         "If you're not part of the solution, you're part of the precipitate." - Henry J. Tillman

Re^2: Cannot print child process command during fork
by whatwhat (Novice) on Aug 02, 2007 at 07:50 UTC
    In my code the system command calls another program to run on the remote node. The program on the remote node can take several hours to run. So I think I need the explicit perl 'fork' command, so that I can start, for example, 24 independent calculations on 24 different compute nodes (computers) all running at the same time.

    I think a loop through system calls would run them serially. Even if system exited without waiting for the program to finish this would be undersirable for my needs. I need the parent process to monitor when the child (the program on the remote node) is finished.

    Thanks for the explanation of 'clobbering'!