SIGCHLD se envía en SIGCONT en Linux pero no en macOS
En el proceso principal escucho SIGCHLD:
signal(SIGCHLD, &my_handler);
Entonces yofork()
, execv()
y dejar que se ejecute en segundo plano (/ bin / cat, por ejemplo).
Cuando intento desde la terminal enviar SIGSTOP al proceso secundario,my_handler()
se llama. Pero cuando trato de enviarle SIGCONT, el controlador no se llama en macOS sino que se ejecuta en mi Ubuntu.
Hombre:
SIGCHLD: el estado del niño ha cambiado.
¿Me estoy perdiendo de algo? ¿Es un comportamiento esperado? Escribí mi aplicación en Ubuntu y esperaba que funcionara también en Mac.
Lo intenté consigaction()
también, pero con los mismos resultados.
Aquí hay un código de muestra para demostrar:
#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;
}
Con la salida en macOS:
Sending 17
SIGCHLD received
Sent 17
Sending 19
Sent 19