i am asked to find all the possible outputs in this question:
Code:#define N 4 int val = 9; void handler(sig) { val += 3; return;} int main() { pid_t pid; int i; signal(SIGCHLD,handler); for (i=0;i<N;i++) { if ((pid =fork()) == 0) { val -= 3; exit(0); } } for (i=0;i<N;i++) { waitpid(-1,NULL,0); } printf("val = %d\n",val); }
I do not know what the line signal(SIGCHLD, handler) does. I only found the following:
SIGABRT - abnormal termination.
SIGFPE - floating point exception.
SIGILL - invalid instruction.
SIGINT - interactive attention request sent to the program.
SIGSEGV - invalid memory access.
SIGTERM - termination request sent to the program.
what does SIGCHLD do? Can you also explain the for loop in this question as well?
and what necessary libraries do I need to compile and run this code?



LinkBack URL
About LinkBacks


