Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include “csapp.h”
- int count = 0;
- void handler_usr1(int sig) { count += 1; }
- void handler_usr2(int sig) { count -= 1; }
- int main(void) {
- pid_t pid;
- int status;
- Signal(SIGUSR1, handler_usr1);
- Signal(SIGUSR2, handler_usr2);
- if ((pid = Fork()) == 0) {
- printf("1");
- Kill(getppid(), SIGUSR1);
- } else {
- printf("2");
- Kill(pid, SIGUSR2);
- }
- if (pid == 0){
- if ((pid = Fork()) == 0){
- printf("3");
- Kill(getppid(), SIGUSR1);
- } else {
- printf("4");
- Kill(pid, SIGUSR2);
- }
- }
- if (pid > 0) {
- while(Waitpid(-1,&status,0) > 0) {
- if (!WIFEXITED(status))
- printf("child terminated abnormally!n");
- }
- }
- printf(“n”);
- // printf("Count: %d n", count);
- }
Add Comment
Please, Sign In to add comment