in reply to Re: Split process->check ->and run Parallel
in thread Split process->check ->and run Parallel

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
  • Comment on Re^2: Split process->check ->and run Parallel

Replies are listed 'Best First'.
Re^3: Split process->check ->and run Parallel
by kyle (Abbot) on Dec 24, 2008 at 16:06 UTC

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

Re^3: Split process->check ->and run Parallel
by roboticus (Chancellor) on Dec 24, 2008 at 15:23 UTC
    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.

      :)