Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <unistd.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- int done;
- void handleSigusr1() {
- puts("Received SIGUSR1");
- done = 1;
- }
- void kidProc() {
- struct sigaction sa;
- memset(&sa, 0, sizeof(struct sigaction));
- sa.sa_handler = &handleSigusr1;
- if (sigaction(SIGUSR1, &sa, NULL)) {
- perror("sigaction");
- exit(1);
- }
- while (!done) sleep(1);
- }
- int main(int argc, char *argv[]) {
- pid_t pid = fork();
- if (pid == -1) {
- perror("");
- exit(-1);
- }
- if (pid == 0) {//kid
- kidProc();
- exit(0);
- }
- sleep(2);
- kill(pid, SIGUSR1);
- int stat;
- wait(&stat);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement