title: C/bash: signal one process on the death of another
body: <p>Think of this as a continuation of the good advice here:
  <a href="https://stackoverflow.com/a/56780616/16739703">https://stackoverflow.com/a/56780616/16739703</a>
  except that I am hoping not to modify the child process.</p>
  <p>Edit: I have written code which minimises to:</p>
  <pre><code>#include &lt;errno.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(int argc, char *argv[], char *envp[]) {
  
    int init_flags=fcntl(0, F_GETFL, 0);
  
    if (fcntl(0, F_SETFL, init_flags | O_ASYNC)) {
      perror(&quot;fcntl...F_SET_FL....O_ASYNC&quot;);
      exit(1);
    }
  
    if (fcntl(0, F_SETOWN, getpid())) {
      perror(&quot;fcntl...F_SETOWN...)&quot;);
      exit(1);
    }
  
  
    if (execve(argv[1], argv+1, envp)) {
      perror(&quot;execve&quot;);
      exit(1);
    }
  
    return 1;
  }
  </code></pre>
  <p>and this makefile:</p>
  <pre><code>all: morehup
  
  CFLAGS=-g -D_GNU_SOURCE
  
  LDFLAGS=-g
  </code></pre>
  <p>so that, with this procedure:</p>
  <pre><code>parent&gt; export TMPDIR=&quot;$(mktemp -d)&quot;
  parent&gt; mkfifo $TMPDIR/fifo
  parent&gt; sh
   # you get a new shell, probably with a different prompt
  parent&gt; exec 7&lt;&gt;$TMPDIR/fifo
   # must be both input and output, or the process stalls
  
  child&gt; TMPDIR=...   # as other shell    
  child&gt; ./morehup &lt;$TMPDIR/fifo /bin/sh -c &quot;while true; do date; sleep 5; done&quot;
  # you get a list of dates
  
  parent&gt; exit
  
  child&gt; I/O possible  # followed by a prompt, with no more dates
  </code></pre>
  <p>the kernel will kill the child when the parent exits.</p>
  <p>The more configurable version is here:
  <a href="https://github.com/JamesC1/morehup/blob/main/morehup.c" rel="nofollow noreferrer">https://github.com/JamesC1/morehup/blob/main/morehup.c</a></p>
  <p>I have two questions:</p>
  <p>What are the chances of adding modest amounts of code, so that this will mostly work for most of the common *nix?</p>
  <p>Is there a posix utility that already does something like this?  ie am I reinventing the wheel, and if so, what is it called?</p>