I dont understand why my code does not work.
This is my code. I don't know why I'm get an error segment. Could somebody explain the reason to me?
#include <iostream>
#include <string>
#include <sys/types.h>
#include <unistd.h>
int id_process;
void manager_signal () {
kill (id_process, SIGKILL);
kill (getppid(),SIGKILL);
}
int main () {
id_process = fork ();
if (id_process==-1) {
perror("ERROR to create the fork");
} else {
if ( id_process != 0 ) {
printf("Father´s ID is %d \n", getpid());
alarm(5);
(void) signal (SIGALRM, manager_signal);
sleep (20);
printf ("Running to where the father can be\n");
alarm (0);
} else {
printf ("CHildren´s ID is %d \n", getpid ());
for (;;) {
printf ( "Children RUN FOREVER ^^");
sleep (2);
}
}
}
return 0;
}