Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a great number of ways to do this, all involving some form of inter-process communication. Which one you choose will depend on many factors, but some are:</p> <ul> <li>shared memory.</li> <li>pipes (<code>popen</code> and such).</li> <li>sockets.</li> </ul> <p>In general, I would probably <code>popen</code> a number of communications sessions in the parent before spawning the children; the parent will know about all five but each child can be configured to use only one.</p> <p>Shared memory is also a possibility, although you'd probably have to have a couple of values in it per child to ensure communications went smoothly:</p> <ul> <li>a value to store the variable and return value.</li> <li>a value to store the state (0 = start, 1 = variable ready for child, 2 = variable ready for parent again).</li> </ul> <p>In all cases, you need a way for the children to only pick up their values, not those destined for other children. That may be as simple as adding a value to the shared memory block to store the PID of the child. All children would scan every element in the block but would only process those where the state is 1 and the PID is their PID.</p> <p>For example:</p> <ul> <li>Main creates shared memory for five children. Each element has state, PID and value.</li> <li>Main sets all states to "start".</li> <li>Main starts five children who all attach to the shared memory.</li> <li>Main stores all their PIDs.</li> <li>All children start scanning the shared memory for state = "ready for child" and their PID.</li> <li>Main puts in first element (state = "ready for child", PID = pid1, value = 7).</li> <li>Main puts in second element (state = "ready for child", PID = pid5, value = 9).</li> <li>Child pid1 picks up first element, changes value to 49, sets state to "ready for parent"), goes back to monitoring.</li> <li>Child pid5 picks up second element, changes value to 81, sets state to "ready for parent"), goes back to monitoring.</li> <li>Main picks up pid5's response, sets that state back to "start.</li> <li>Main picks up pid1's response, sets that state back to "start.</li> </ul> <p>This gives a measure of parallelism with each child continuously monitoring the shared memory for work it's meant to do, Main places the work there and periodically receives the results.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload