Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can call <code>setpgid()</code> in the forked child process that will execute the shell script. That will give any spawned processes from that shell script the same group ID as the child process. You can then use <code>killpg()</code> to send a signal to the entire group that all processes in that group will receive.</p> <p>For instance, if inside the child process you called <code>setpgid(0, 0)</code>, this would setup a special instance where the child-process' group ID will be set to the same value as the child's PID. Then any processes overlaid on the child process using one of the <code>exec</code> family of functions will have the same group-ID value that the child had. In addition, any processes that the newly overlaid process may spawn will also have the same group ID (i.e., your shell-script). You can then, using <code>killpg()</code>, send a signal to any processes sharing a group ID value using just the child's PID value that <code>fork()</code> returned since the group ID of the child process is the same value as the child's PID after the <code>setpgid(0, 0)</code> call.</p> <p>If you are using <code>fork()</code>, depending on how quickly you need to send signals to the group from the parent process may create some synchronization issues ... for example, you want to immediately send a signal to the process group right after forking the child process. There are two work-arounds for this: Either 1) use <code>vfork()</code> instead of fork, so that the parent is suspended until the child has changed it's group-ID and successfully called <code>exec</code>, or 2) call <code>setpgid()</code> in the parent process <em>as well as</em> in the child-process, but in the parent, rather than using <code>setgpid(0, 0)</code> like you would in the child, you can use <code>setpgid(CHILD_PID, CHILD_PID)</code>. Then it won't matter which call was successful (one of them will be successful, and the other will fail with a <code>EACCES</code>), and any successive signals sent from the parent wil now go to a valid group ID.</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. 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