Skip to content

Commit af9294c

Browse files
committed
terminated children do not become zombies on Linux
signal(SIGCHLD, SIG_IGN); https://man7.org/linux/man-pages/man2/sigaction.2.html 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)). Nevertheless, the historical BSD and System V behaviors for ignoring SIGCHLD differ, so that the only completely portable method of ensuring that terminated children do not become zombies is to catch the SIGCHLD signal and perform a wait(2) or similar.
1 parent c8e2e00 commit af9294c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

flang/runtime/execute.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <stdio.h>
2222
#include <windows.h>
2323
#else
24+
#include <signal.h>
2425
#include <unistd.h>
2526
#endif
2627

@@ -223,6 +224,8 @@ void RTNAME(ExecuteCommandLine)(const Descriptor *command, bool wait,
223224
}
224225
delete[] wcmd;
225226
#else
227+
// terminated children do not become zombies
228+
signal(SIGCHLD, SIG_IGN);
226229
pid_t pid{fork()};
227230
if (pid < 0) {
228231
if (!cmdstat) {

0 commit comments

Comments
 (0)