--- 4.karina.18_test.coder.fmt.c 2020-06-08 11:39:11.758115926 +0300
+++ 4.egor.18_test.coder.fmt.c 2020-06-08 11:39:11.727115591 +0300
@@ -1,29 +1,29 @@
#1 "<stdin>"
-#include <stdio.h>
#include <string.h>
-#include <signal.h>
+#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
+#include <stdio.h>
+#include <signal.h>
#include <stdlib.h>
-#include <errno.h>
int main(int argc, char *argv[]) {
- int signal = 0;
+ int sygnal = 0;
while (1) {
- char c0 = argv[2][signal];
- char c1 = argv[2][signal];
- int PID = (atoi(argv[1]));
- for (int i = 7; i >= 0; i--) {
- int a = (c0 >> (i)) & 0x1;
- if (a == 1)
- kill(PID, SIGUSR2);
+ char zero = argv[2][sygnal];
+ char one = argv[2][sygnal];
+ int pid = (atoi(argv[1]));
+ for (int k = 7; k >= 0; k--) {
+ int x = (zero >> (k)) & 0x1;
+ if (x == 1)
+ kill(pid, SIGUSR2);
else
- kill(PID, SIGUSR1);
+ kill(pid, SIGUSR1);
usleep(10000);
- c0 = c0 << 1;
+ zero = zero << 1;
}
- if (c1 == 0)
+ if (one == 0)
break;
- signal++;
+ sygnal++;
}
return 0;
}
--- 4.karina.18_test.decoder.fmt.c 2020-06-08 11:39:11.762115970 +0300
+++ 4.egor.18_test.decoder.fmt.c 2020-06-08 11:39:11.730115623 +0300
@@ -1,33 +1,26 @@
#1 "<stdin>"
+#include <assert.h>
+#include <signal.h>
+#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <stdbool.h>
-int global = 0;
-int x = 1;
-char c = 0;
-void func(int sig) {
- if (sig == SIGUSR1)
+int current = 0;
+char c = '\0';
+void overhandler(int sig) {
+ if (sig == SIGUSR1) {
c = c << 1;
- else if (sig == SIGUSR2)
+ } else if (sig == SIGUSR2) {
c = ((c << 1) + 1);
- global++;
- if (global == 8) {
- if (c == 0) {
- x = 0;
- return;
- }
- global = 0;
- printf("%c", c);
}
+ current++;
}
int main(int argc, char *argv[]) {
printf("PID: %d\n", getpid());
- signal(SIGUSR1, func);
- signal(SIGUSR2, func);
+ signal(SIGUSR1, overhandler);
+ signal(SIGUSR2, overhandler);
for (int i = 0;; i++)
sleep(1);
return 0;