O SIGCHLD é enviado no SIGCONT no Linux, mas não no macOS
No processo principal, eu escuto o SIGCHLD:
signal(SIGCHLD, &my_handler);
Então eufork()
, execv()
e deixe executar em segundo plano (/ bin / cat, por exemplo).
Quando tento do terminal enviar SIGSTOP para o processo filho,my_handler()
é chamado. Mas quando tento enviar o SIGCONT para ele, o manipulador não é chamado no macOS, mas é executado no meu Ubuntu.
Cara:
SIGCHLD: o status filho mudou.
Estou esquecendo de algo? É um comportamento esperado? Eu escrevi meu aplicativo no Ubuntu e esperava que ele funcionasse no mac também.
Eu tentei comsigaction()
também, mas com os mesmos resultados.
Aqui está um código de exemplo para demonstrar:
#include <signal.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
void my_handler(int signum)
{
printf("\t SIGCHLD received\n");
fflush(stdout);
}
void my_kill(pid_t pid, int signum)
{
printf("Sending %d\n", signum);
fflush(stdout);
kill(pid, signum);
printf("Sent %d\n\n", signum);
fflush(stdout);
}
int main()
{
pid_t pid;
char *cat_args[2] = {"/bin/cat", NULL};
signal(SIGCHLD, &my_handler);
pid = fork();
if (pid == 0)
{
execv("/bin/cat", cat_args);
}
else
{
my_kill(pid, SIGSTOP);
my_kill(pid, SIGCONT);
wait(NULL);
}
return 0;
}
Com a saída no macOS:
Sending 17
SIGCHLD received
Sent 17
Sending 19
Sent 19