/*This is a demo of how signals work in c *This program forks off a child process (pid 0), and then has the *both the child and the parent print lines. *For this pogram, the parent waits until the child prints a line *before printing its own line. After the child prints a line, the child *sends a signal to the parent that it has stopped (SIGSTOP) *The parent has been instructed to wait until it gets a message *from the child that the child has stopped (waitpid). It prints a line *then sends a message back to the child to continue (SIGCONT). The parent *loop then goes back into a waiting state for the child to printthe next line*/ #include #include #include #include int main() { int pid, count, status; pid = fork(); switch(pid) { case 0: /* Child process */{ for(count=1; count<3; count++){ printf("Hello, I am the child & this is message #%d\n", count); sleep(1); kill(getpid(), SIGSTOP); } break; } default: /* Parent process */ { for(count=1; count<3; count++){ waitpid(pid,&status,WUNTRACED); printf("Hello! I am the parent and this is message#%d\n", count); sleep(1); kill(pid, SIGCONT); } break; } } return(0); }