Turn On/Off pids on notifying other processes. master
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 21 Jun 2014 19:38:04 +0000 (21:38 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 21 Jun 2014 19:38:04 +0000 (21:38 +0200)
src/process1.c
src/process2.c
src/process3.c

index e440107e4e83c83be1bb1fddcacd1ec6ebe07060..69e6bda8ab4d0189e491aeb87b817769e83ce72c 100644 (file)
@@ -106,7 +106,7 @@ void sig_handler(int signo)
        }
        else if (signo == SIGTERM) {
                fprintf(stderr, "[%s] > Signalling other processes..\n", "process1");
        }
        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");
                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) {
                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);
                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);
        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();
        }
 }
 
        }
 }
 
index 03aea04af4ae7233f54d1ee3fcb70d469358add5..5f5e14d4d20a461952882424bc8cf60cce1b837c 100644 (file)
@@ -122,14 +122,21 @@ void sig_handler(int signo)
        else if (signo == SIGTSTP) {
                fprintf(stderr, "[%s] > Close reading pipe\n", "process2");
                close(read_descriptor);
        else if (signo == SIGTSTP) {
                fprintf(stderr, "[%s] > Close reading pipe\n", "process2");
                close(read_descriptor);
+               processes->pids[1] = 0;
                notify_other_processes(signo);
                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");
                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);
                notify_other_processes(signo);
+//             sleep(1);
+               processes->pids[1] = getpid();
 
                fprintf(stderr, "[%s] > Opening pipes\n", "process2");
                write_descriptor = open(write_pipe, O_WRONLY);
 
                fprintf(stderr, "[%s] > Opening pipes\n", "process2");
                write_descriptor = open(write_pipe, O_WRONLY);
index 91212e991a1cc3ff0363e1a8f157fa5df5a7bc8b..1357c91b5ab5bedd439948ac3a8c9780abe128e6 100644 (file)
@@ -112,7 +112,10 @@ void sig_handler(int signo)
        }
        else if (signo == SIGTSTP) {
                fprintf(stderr, "[%s] > Signalling other processes..\n", "process3");
        }
        else if (signo == SIGTSTP) {
                fprintf(stderr, "[%s] > Signalling other processes..\n", "process3");
+               processes->pids[2] = 0;
                notify_other_processes(signo);
                notify_other_processes(signo);
+//             sleep(1);
+               processes->pids[2] = getpid();
 
                fprintf(stderr, "[%s] > Closing pipe\n", "process3");
                close(read_descriptor);
 
                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");
        }
        else if (signo == SIGCONT) {
                fprintf(stderr, "[%s] > Signalling other processes..\n", "process3");
+               processes->pids[2] = 0;
                notify_other_processes(signo);
                notify_other_processes(signo);
+//             sleep(1);
+               processes->pids[2] = getpid();
 
                fprintf(stderr, "[%s] > Opening pipe\n", "process3");
                read_descriptor = open(read_pipe, O_RDONLY);
 
                fprintf(stderr, "[%s] > Opening pipe\n", "process3");
                read_descriptor = open(read_pipe, O_RDONLY);