4.karina.18_test.decoder 4.ilyaz.18_test.decoder

--- 4.karina.18_test.coder.fmt.c	2020-06-08 11:39:11.758115926 +0300
+++ 4.ilyaz.18_test.coder.fmt.c	2020-06-08 11:39:11.742115753 +0300
@@ -1,29 +1,25 @@
 #1 "<stdin>"
 #include <stdio.h>
-#include <string.h>
-#include <signal.h>
 #include <sys/types.h>
+#include <signal.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <errno.h>
+#include <string.h>
 int main(int argc, char *argv[]) {
-    int signal = 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 *c = argv[2];
+    int pid;
+    sscanf(argv[1], "%d", &pid);
+    int len = strlen(c) + 1;
+    *(c + len) = '\0';
+    for (int i = 0; i < len; ++i) {
+	for (int j = 7; j >= 0; --j) {
+	    int byte = (c[i] >> j) & 1;
+	    if (byte == 1)
+		kill(pid, SIGUSR2);
 	    else
-		kill(PID, SIGUSR1);
-	    usleep(10000);
-	    c0 = c0 << 1;
+		kill(pid, SIGUSR1);
+	    usleep(1000);
 	}
-	if (c1 == 0)
-	    break;
-	signal++;
     }
     return 0;
 }
--- 4.karina.18_test.decoder.fmt.c	2020-06-08 11:39:11.762115970 +0300
+++ 4.ilyaz.18_test.decoder.fmt.c	2020-06-08 11:39:11.746115796 +0300
@@ -1,34 +1,32 @@
 #1 "<stdin>"
 #include <stdio.h>
-#include <string.h>
-#include <sys/wait.h>
+#include <sys/types.h>
+#include <signal.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)
-	c = c << 1;
-    else if (sig == SIGUSR2)
-	c = ((c << 1) + 1);
-    global++;
-    if (global == 8) {
-	if (c == 0) {
-	    x = 0;
-	    return;
-	}
-	global = 0;
-	printf("%c", c);
+#include <string.h>
+int flag_end = 0;
+char cur_char = 0;
+int length = 0;
+void handler(int signal) {
+    cur_char = cur_char << 1;
+    if (signal == SIGUSR2)
+	cur_char += 1;
+    length += 1;
+    if (length == 8) {
+	if (cur_char == '\0')
+	    printf("\n");
+	length = 0;
+	printf("%c", cur_char);
+	fflush(stdout);
     }
 }
 int main(int argc, char *argv[]) {
-    printf("PID: %d\n", getpid());
-    signal(SIGUSR1, func);
-    signal(SIGUSR2, func);
-    for (int i = 0;; i++)
+    int pid = getpid();
+    printf("My PID: %d\n", pid);
+    signal(SIGUSR1, handler);
+    signal(SIGUSR2, handler);
+    while (1)
 	sleep(1);
     return 0;
 }