Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- #include <sys/types.h>
- #include <unistd.h>
- int a,b,p,fd[2],temp;
- void hndlr(int s)
- {
- sleep(1);
- read(fd[0], &temp, sizeof(int));
- printf("Пишет процесс %d : %d\n", getpid(), temp);
- temp++;
- write(fd[1], &temp, sizeof(int));
- kill(p,SIGUSR1);
- }
- int main()
- {
- // a->parent->b->a...
- signal(SIGUSR1, hndlr);
- pipe(fd);
- a=fork();
- if (a==0) // сын a
- {
- p=getppid();
- temp=1;
- write(fd[1],&temp, sizeof(int));
- kill(p,SIGUSR1);
- while (1)
- {
- }
- }
- else
- {
- b=fork();
- if (b==0) // сын b
- {
- p=a;
- while(1)
- {
- }
- }
- else //parent
- {
- p=b;
- while(1)
- {
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement