[flang-commits] [flang] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

Yi Wu via flang-commits flang-commits at lists.llvm.org
Mon Dec 4 08:09:00 PST 2023


yi-wu-arm wrote:

> That makes sense, given that you want to use `system()` rather than `fork()` and `execvp()`. On the asynchronous POSIX path you're actually creating two processes rather than one, unfortunately.
> 
> Do you ever use `waitpid()` to harvest these completed processes? If not, they'll occupy system resources until the program exits.

After a chat with @DavidTruby, we find that using `signal(SIGCHLD, SIG_IGN)` can prevent creation of zombie child.
https://man7.org/linux/man-pages/man2/sigaction.2.html
```md
SA_NOCLDWAIT (since Linux 2.6)
              If signum is SIGCHLD, do not transform children into
              zombies when they terminate.  See also [waitpid(2)](https://man7.org/linux/man-pages/man2/waitpid.2.html).  This
              flag is meaningful only when establishing a handler for
              SIGCHLD, or when setting that signal's disposition to
              SIG_DFL.

              If the SA_NOCLDWAIT flag is set when establishing a
              handler for SIGCHLD, POSIX.1 leaves it unspecified whether
              a SIGCHLD signal is generated when a child process
              terminates.  On Linux, a SIGCHLD signal is generated in
              this case; on some other implementations, it is not.
POSIX.1-1990 disallowed setting the action for SIGCHLD to
       SIG_IGN.  POSIX.1-2001 and later allow this possibility, so that
       ignoring SIGCHLD can be used to prevent the creation of zombies
       (see [wait(2)](https://man7.org/linux/man-pages/man2/wait.2.html)).
```


https://github.com/llvm/llvm-project/pull/74077


More information about the flang-commits mailing list