in reply to Split process->check ->and run Parallel

Have p1 fork and exec p2. Have p2 write the txt report and then send a signal (with kill and getppid) to p1. After the fork, p1 can just sleep until it gets that signal. It would probably be a good idea to have p1 check that p2 is still alive (with kill or waitpid) once in a while. Once p1 gets its signal, it can do what it wants with the txt report while p2 works on the Excel report. When p1 is ready to wait again, just waitpid for p2 and check its exit status to make sure there was no error.

  • Comment on Re: Split process->check ->and run Parallel

Replies are listed 'Best First'.
Re^2: Split process->check ->and run Parallel
by matrixmadhan (Beadle) on Dec 24, 2008 at 10:32 UTC
    It would probably be a good idea to have p1 check that p2 is still alive (with kill or waitpid) once in a while

    But, why is this needed, if a child process is terminated/killed a SIGCHLD will be delivered to the parent by default, so I don't think an explicit check for the existence of the child process is needed
      matrixmadhan:

      It's me again!

      The kill function doesn't have to terminate another process. There are other signals that it can send. You can send several different signals to another process with it, such as:

      $ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGEMT 8) SIGFPE 9) SIGKILL 10) SIGBUS 11) SIGSEGV 12) SIGSYS 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGURG 17) SIGSTOP 18) SIGTSTP 19) SIGCONT 20) SIGCHLD 21) SIGTTIN 22) SIGTTOU 23) SIGIO 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGLOST 30) SIGUSR1 31) SIGUSR2 32) SIGRTMAX

      If both processes agree on a signal for communication, then you can put a signal handling function in your processes to receive the messages. For example, you could use SIGUSR1 to let P2 tell P1 that the text report is done. Then you could send SIGUSR2 to indicate that the spreadsheet is done.

      ...roboticus
        I agree that communication between parent and child to be established via the signals provided and that would prove to be more robust and synchronous instead of communication being asynchronous when its not needed.

        :)

      You're right. The parent can just trap SIGCHLD and whatever "I'm done" signal the child is sending and sleep.