--- 4.ilyas.18_test.decoder.fmt.c 2020-06-08 11:39:11.738115710 +0300
+++ 4.egor.18_test.decoder.fmt.c 2020-06-08 11:39:11.730115623 +0300
@@ -7,30 +7,21 @@
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
-int done = 1;
-char current = 0;
-int len = 0;
-void signal_handler(int sig) {
- current = current << 1;
- if (sig == SIGUSR2)
- current += 1;
- len += 1;
- if (len == 8) {
- if (current == 0) {
- done = 0;
- return;
- }
- len = 0;
- printf("%c", current);
+int current = 0;
+char c = '\0';
+void overhandler(int sig) {
+ if (sig == SIGUSR1) {
+ c = c << 1;
+ } else if (sig == SIGUSR2) {
+ c = ((c << 1) + 1);
}
+ current++;
}
int main(int argc, char *argv[]) {
- int pid;
- pid = getpid();
- printf("PID: %d\n", pid);
- signal(SIGUSR1, signal_handler);
- signal(SIGUSR2, signal_handler);
- while (done)
+ printf("PID: %d\n", getpid());
+ signal(SIGUSR1, overhandler);
+ signal(SIGUSR2, overhandler);
+ for (int i = 0;; i++)
sleep(1);
return 0;
}