Isolate child process group with setpgid to prevent double signal delivery

This commit is contained in:
Andrea Mazzoleni 2026-08-12 10:04:50 +02:00
parent 4defb748e8
commit 1c3f695d5a

View file

@ -387,6 +387,9 @@ int main(int argc, char* argv[])
if (pid == 0) {
/* child process */
/* isolate child in its own process group to prevent double signal delivery from terminal */
setpgid(0, 0);
/* restore default signal handlers */
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
@ -409,6 +412,9 @@ int main(int argc, char* argv[])
/* parent process */
int status;
/* set child process group in parent to prevent race condition */
setpgid(pid, pid);
/* store child PID so signal handler can forward signals */
child_pid = pid;