Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <signal.h>
- #include <sys/types.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- pid_t pid;
- void f_parent()
- {
- sleep(1);
- printf("Ping..");
- kill(pid, SIGUSR2);
- fflush(stdout);
- }
- void f_child()
- {
- sleep(1);
- printf("Pong\n");
- kill(getppid(), SIGUSR1);
- }
- int main()
- {
- int status;
- printf("Gioco del Ping-Pong tra padre e figlio\n\n");
- signal(SIGUSR1, f_parent);
- pid = fork();
- switch(pid)
- {
- case -1:
- perror("Fork failed: ");
- exit(1);
- break;
- case 0: // Figlio
- signal(SIGUSR2, f_child);
- while(1);
- break;
- default: // Padre
- sleep(1);
- kill(getpid(), SIGUSR1);
- wait(&status);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement