I think that it will not crash. But it crash sometimes.
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
void sig_child(int s)
{
printf("test here\n");
fflush(stdout);
int status = 0;
wait(&status);
}
int main()
{
signal(SIGCHLD, sig_child);
pid_t id = fork();
if (id < 0)
{
printf("fork error.\n");
fflush(stdout);
}
else if (id == 0)
{
exit(0);
}
else
{
printf("%d\n", id);
fflush(stdout);
}
}
my test bash
for ((i=1; i<=1000; i++))
do
./a.out
done
sometimes, the program will crash as the following:
Segmentation fault
you test test it on your computer1
you test test it on your computer2
you test test it on your computer3
you test test it on your computer4
you test test it on your computer5
you test test it on your computer6