From: Rafał Długołęcki Date: Sat, 21 Jun 2014 19:38:04 +0000 (+0200) Subject: Turn On/Off pids on notifying other processes. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=2a3a69b2ecc61d45586cb8f15435255d998573ac;p=wsti_so.git Turn On/Off pids on notifying other processes. --- diff --git a/src/process1.c b/src/process1.c index e440107..69e6bda 100644 --- a/src/process1.c +++ b/src/process1.c @@ -106,7 +106,7 @@ void sig_handler(int signo) } else if (signo == SIGTERM) { fprintf(stderr, "[%s] > Signalling other processes..\n", "process1"); - processes->pids[1] = 0; + processes->pids[0] = 0; notify_other_processes(signo); fprintf(stderr, "[%s] > Releasing resources\n", "process1"); @@ -120,6 +120,12 @@ void sig_handler(int signo) exit(0); } else if (signo == SIGTSTP) { + fprintf(stderr, "[%s] > Signalling other processes..\n", "process1"); + processes->pids[0] = 0; + notify_other_processes(signo); +// sleep(1); + processes->pids[0] = getpid(); + fprintf(stderr, "[%s] > Closing pipe\n", "process1"); close(write_pipe); raise (SIGSTOP); @@ -127,6 +133,10 @@ void sig_handler(int signo) else if (signo == SIGCONT) { fprintf(stderr, "[%s] > Opening pipe\n", "process1"); file_descriptor = open(write_pipe, O_WRONLY); + processes->pids[0] = 0; + notify_other_processes(signo); +// sleep(1); + processes->pids[0] = getpid(); } } diff --git a/src/process2.c b/src/process2.c index 03aea04..5f5e14d 100644 --- a/src/process2.c +++ b/src/process2.c @@ -122,14 +122,21 @@ void sig_handler(int signo) else if (signo == SIGTSTP) { fprintf(stderr, "[%s] > Close reading pipe\n", "process2"); close(read_descriptor); + processes->pids[1] = 0; notify_other_processes(signo); +// sleep(1); + processes->pids[1] = getpid(); + fprintf(stderr, "[%s] > Close writing pipe\n", "process2"); close(write_descriptor); raise (SIGSTOP); } else if (signo == SIGCONT) { fprintf(stderr, "[%s] > Signalling other processes..\n", "process2"); + processes->pids[1] = 0; notify_other_processes(signo); +// sleep(1); + processes->pids[1] = getpid(); fprintf(stderr, "[%s] > Opening pipes\n", "process2"); write_descriptor = open(write_pipe, O_WRONLY); diff --git a/src/process3.c b/src/process3.c index 91212e9..1357c91 100644 --- a/src/process3.c +++ b/src/process3.c @@ -112,7 +112,10 @@ void sig_handler(int signo) } else if (signo == SIGTSTP) { fprintf(stderr, "[%s] > Signalling other processes..\n", "process3"); + processes->pids[2] = 0; notify_other_processes(signo); +// sleep(1); + processes->pids[2] = getpid(); fprintf(stderr, "[%s] > Closing pipe\n", "process3"); close(read_descriptor); @@ -120,7 +123,10 @@ void sig_handler(int signo) } else if (signo == SIGCONT) { fprintf(stderr, "[%s] > Signalling other processes..\n", "process3"); + processes->pids[2] = 0; notify_other_processes(signo); +// sleep(1); + processes->pids[2] = getpid(); fprintf(stderr, "[%s] > Opening pipe\n", "process3"); read_descriptor = open(read_pipe, O_RDONLY);