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>
- void f_parent()
- {
- printf("Ping\n");
- }
- void f_child()
- {
- printf("Pong\n");
- }
- int main()
- {
- pid_t pid; int stat;
- pid = fork();
- if(pid < 0) // ERROR
- {
- perror("Fork error: ");
- exit(1);
- }
- else if(pid == 0) // CHILD
- {
- signal(SIGUSR2, f_child);
- kill(getpid(), SIGUSR2);
- }
- else // PARENT
- {
- signal(SIGUSR1, f_parent);
- kill(getpid(), SIGUSR1);
- wait(&stat);
- kill(pid, SIGUSR2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement