Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <termios.h>
- void print0()
- {
- printf("a");
- }
- void print1()
- {
- printf("b");
- }
- int main(void)
- {
- struct termios mode;
- tcgetattr(0,&mode);
- mode.c_lflag &= ~ECHO;
- mode.c_lflag &= ~ICANON;
- tcsetattr(0, TCSANOW, &mode);
- setbuf(stdout,NULL);
- pid_t pid = fork();
- if(pid == 0)
- {
- signal(SIGUSR1, print0);
- signal(SIGUSR2, print1);
- //alarm(100);
- while(1)
- pause();
- }
- else
- {
- while(1)
- {
- char c = getchar();
- if(c == '0') kill(pid, SIGUSR1);
- else if(c == '1') kill(pid, SIGUSR2);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement