Reputation: 31
I can not figure out what I have wrong with this code. This is C on a linux box.
What it should do is kill all the child processes I created, wait for the all to quit and then print out a line for each child with the pid, process number (I create), and the signal number (should be a 9 for killed).
So what am I doing wrong?
void onalarm(int signo) {
int status[numberOfCores];
printf("Recieved alarm signal\n");
int cpu;
for (cpu = 0; cpu < numberOfCores; cpu++) {
kill(child_pid[cpu], SIGKILL);
}
for (cpu=0;cpu <numberOfCores;cpu++){
waitpid(-1, &status[numberOfCores],0);
}
for (cpu=0;cpu < numberOfCores;cpu++){
printf("pid = %i %ith child killed with signal ",child_pid[cpu],cpu);
printf("%i %s\n", WTERMSIG(status[cpu]), strsignal(WTERMSIG(status[cpu])));
}
exit(0);
Upvotes: 0
Views: 1551
Reputation: 31
I figured out what my problem was.
for (cpu=0;cpu <numberOfCores;cpu++){
waitpid(-1, &status[numberOfCores],0);
Should be.
for (cpu=0;cpu <numberOfCores;cpu++){
waitpid(-1, &status[cpu],0);
Got it working correctly know. Thanks for helping me think.
Upvotes: 1