title: Print int from signal handler using write or async-safe functions
body: <p>I want to print a number into log or to a terminal using <code>write</code> (or any async-safe function) inside a signal handler. I would prefer not to use buffered I/O.</p>
  
  <p>Is there an easy and recommended way to do that ?</p>
  
  <p>For example in place of <code>printf</code>, below I would prefer <code>write</code> (or any asyn safe function).</p>
  
  <pre><code>void signal_handler(int sig)
  {
    pid_t pid;
    int stat;
    int old_errno = errno;
  
    while((pid = waitpid(-1, &amp;stat, WNOHANG)) &gt; 0)
      printf("child %d terminated\n", pid);
  
    errno = old_errno;
    return;
  }
  </code></pre>
  
  <p>Printing strings is easy. In place of the <code>printf</code> above I can use (without printing <code>pid</code>):</p>
  
  <pre><code>write(STDOUT_FILENO, "child terminated", 16);
  </code></pre>