Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // program for input
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <signal.h>
- #define ER(number) { \
- printf("E%d\n", number); \
- exit(-1); \
- }
- int i;
- int j = 0;
- pid_t pid1;
- void handler(int n) {
- if (j == 33) return;
- if (n == SIGUSR1) {
- int bit;
- bit = (i<<j)>>31;
- if (bit == -1) {
- if (kill(pid1, SIGUSR1) < 0) ER(1);
- }
- else if (bit == 0) {
- if (kill(pid1, SIGUSR2) < 0) ER(2);
- }
- else ER(3);
- ++j;
- }
- }
- int main() {
- printf("%d\n", getpid());
- scanf("%d", &pid1);
- scanf("%d", &i);
- signal(SIGUSR1, handler);
- handler(SIGUSR1);
- while(j < 32);
- return 0;
- }
- // program for output
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <signal.h>
- #define ER(number) { \
- printf("E%d\n", number); \
- exit(-1); \
- }
- int j = 0;
- int i = 0;
- pid_t pid0;
- void handler (int n) {
- if (j == 32) return;
- i <<= 1;
- if (n == SIGUSR1)
- i += 1;
- // if (n == SIGUSR2) i += 0;
- if (kill (pid0, SIGUSR1) < 0) ER(1);
- ++j;
- }
- int main() {
- printf("%d\n", getpid());
- scanf("%d", &pid0);
- signal(SIGUSR1, handler);
- signal(SIGUSR2, handler);
- while(j < 32);
- printf("%d\n", i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment