Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What does the following C program print and why? Note that emphasis of this ques

ID: 3819833 • Letter: W

Question

What does the following C program print and why? Note that emphasis of this question is on your understanding of the signal functionality. State your assumptions where necessary. pid_t pid; void h1(int sig) { printf(eagle); kill(pid, SIGUSR2); } void h2(int sig) { printf (sparrow); exit(0); } main () { signal(SIGUSR2, h1); if ((pid = fork()) == 0) { signal(SIGUSR2, h2); kill(getppid(), SIGUSR2); while(1) {}; } else { pid_t p; int status; if ((p = wait(&status;)) > 0) { printf(pigeon); } } }

Explanation / Answer

OUTPUT

Output of the above program is eaglesparrow

EXPLANATION

Starting from the main:

Note that kill() is used to send signals to processes and not terminate it.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote