Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <string.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- void sigusr1(int sig, siginfo_t *info, void *extra)
- {
- void *ptr = info->si_value.sival_ptr;
- printf("1\n");
- }
- void firstProcess()
- {
- struct sigaction action;
- action.sa_flags = SA_SIGINFO;
- action.sa_sigaction = &sigusr1;
- sigset_t oldset;
- sigemptyset(&action.sa_mask);
- sigaddset(&action.sa_mask, SIGUSR1);
- sigemptyset(&oldset);
- sigprocmask(SIG_BLOCK, &action.sa_mask, &oldset);
- if (sigaction(SIGUSR1, &action, 0) == -1) {
- exit(1);
- }
- int sig = 0;
- sigwait(&action.sa_mask, &sig);
- printf("%d\n", sig);
- exit(0);
- }
- void secondProcess()
- {
- int i;
- exit(0);
- }
- int main(int argc, char *argv[])
- {
- pid_t pid1, pid2, pid3;
- pid_t *arrpid;
- pid1 = fork();
- struct sigaction actStc;
- memset(&actStc, 0, sizeof(actStc));
- // actStc.sa_handler = firsthdl;
- //sigset_t set;
- sigemptyset(&actStc.sa_mask);
- sigaddset(&actStc.sa_mask, SIGUSR1);
- sigaction(SIGUSR1, &actStc, 0);
- //wait(NULL);
- // printf("%ld\n", strlen(argv[1]));
- if (pid1 == 0) {
- firstProcess();
- } else {
- sleep(1);
- union sigval sigUn;
- sigUn.sival_ptr = argv[1];
- sigqueue(pid1, SIGUSR1, sigUn);
- // kill(pid1, SIGUSR1);
- pid2 = fork();
- if (pid2 == 0) {
- secondProcess();
- } else {
- pid3 = fork();
- if (pid3 == 0) {
- //for ( ; ; );
- } else {
- //sleep(10);
- }
- }
- }
- //printf("%d\n", getSig);
- sleep(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement