Replace SIGINT with SIGTSTP.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 21 Jun 2014 05:51:01 +0000 (07:51 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 21 Jun 2014 05:51:01 +0000 (07:51 +0200)
src/process1.c
src/process2.c
src/process3.c

index fbee7c9f22ad04dbabd5a456a60cae3cfb988a7e..aa27e8cf8857c9466c41e909cd1407a8906edda0 100644 (file)
@@ -25,11 +25,10 @@ int file_descriptor;
  */
 void sig_handler(int signo)
 {
+       fprintf(stderr, "[%s] Received %s!\n", "process1", strsignal(signo));
        if (signo == SIGUSR1) {
-               fprintf(stderr, "[%s] Received SIGUSR1!\n", "process1");
        }
        else if (signo == SIGTERM) {
-               fprintf(stderr, "[%s] Received SIGTERM!\n", "process1");
                fprintf(stderr, "[%s] > Releasing resources\n", "process1");
                close(write_pipe);
                unlink(write_pipe);
@@ -40,13 +39,11 @@ void sig_handler(int signo)
                }
                exit(0);
        }
-       else if (signo == SIGINT) {
-               fprintf(stderr, "[%s] Received SIGINT!\n", "process1");
+       else if (signo == SIGTSTP) {
                fprintf(stderr, "[%s] > Closing pipe\n", "process1");
                close(write_pipe);
        }
        else if (signo == SIGCONT) {
-               fprintf(stderr, "[%s] Received SIGCONT!\n", "process1");
                fprintf(stderr, "[%s] > Opening pipe\n", "process1");
                file_descriptor = open(write_pipe, O_WRONLY);
        }
@@ -83,8 +80,8 @@ int main(void) {
        if (signal(SIGTERM, sig_handler) == SIG_ERR) {
                fprintf(stderr, "can't catch SIGTERM\n");
        }
-       if (signal(SIGINT, sig_handler) == SIG_ERR) {
-               fprintf(stderr, "can't catch SIGINT\n");
+       if (signal(SIGTSTP, sig_handler) == SIG_ERR) {
+               fprintf(stderr, "can't catch SIGTSTP\n");
        }
        if (signal(SIGCONT, sig_handler) == SIG_ERR) {
                fprintf(stderr, "can't catch SIGCONT\n");
index 75dacfde993ab2fa3f29357ac1fa335896dd827a..87871e78675ecf56fa35ee9a4df9ab2712c667e7 100644 (file)
@@ -28,25 +28,22 @@ int write_descriptor;
  */
 void sig_handler(int signo)
 {
+       fprintf(stderr, "[%s] Received %s!\n", "process2", strsignal(signo));
        if (signo == SIGUSR1) {
-               fprintf(stderr, "[%s] Received SIGUSR1!\n", "process2");
        }
        else if (signo == SIGTERM) {
-               fprintf(stderr, "[%s] Received SIGTERM!\n", "process2");
                fprintf(stderr, "[%s] > Releasing resources\n", "process2");
                close(read_descriptor);
                close(write_descriptor);
                unlink(write_descriptor);
                exit(0);
        }
-       else if (signo == SIGINT) {
-               fprintf(stderr, "[%s] Received SIGINT!\n", "process2");
+       else if (signo == SIGTSTP) {
                fprintf(stderr, "[%s] > Closing pipes\n", "process2");
                close(read_descriptor);
                close(write_descriptor);
        }
        else if (signo == SIGCONT) {
-               fprintf(stderr, "[%s] Received SIGCONT!\n", "process2");
                fprintf(stderr, "[%s] > Opening pipes\n", "process2");
                read_descriptor = open(read_pipe, O_RDONLY);
                write_descriptor = open(write_pipe, O_WRONLY);
@@ -85,8 +82,8 @@ int main(void) {
        if (signal(SIGTERM, sig_handler) == SIG_ERR) {
                fprintf(stderr, "can't catch SIGTERM\n");
        }
-       if (signal(SIGINT, sig_handler) == SIG_ERR) {
-               fprintf(stderr, "can't catch SIGINT\n");
+       if (signal(SIGTSTP, sig_handler) == SIG_ERR) {
+               fprintf(stderr, "can't catch SIGTSTP\n");
        }
        if (signal(SIGCONT, sig_handler) == SIG_ERR) {
                fprintf(stderr, "can't catch SIGCONT\n");
index de70b8d372b43f807c595d5ce8298c37253a7556..b75f903af10e363d5c96d07000fa22609322f025 100644 (file)
@@ -20,23 +20,20 @@ int read_descriptor;
  */
 void sig_handler(int signo)
 {
+       fprintf(stderr, "[%s] Received %s!\n", "process3", strsignal(signo));
        if (signo == SIGUSR1) {
-               fprintf(stderr, "[%s] Received SIGUSR1!\n", "process3");
        }
        else if (signo == SIGTERM) {
-               fprintf(stderr, "[%s] Received SIGTERM!\n", "process3");
                fprintf(stderr, "[%s] > Releasing resources\n", "process3");
                close(read_descriptor);
                exit(0);
        }
-       else if (signo == SIGINT) {
-               fprintf(stderr, "[%s] Received SIGINT!\n", "process3");
-               fprintf(stderr, "[%s] > Closing pipe\n", "process2");
+       else if (signo == SIGTSTP) {
+               fprintf(stderr, "[%s] > Closing pipe\n", "process3");
                close(read_descriptor);
        }
        else if (signo == SIGCONT) {
-               fprintf(stderr, "[%s] Received SIGCONT!\n", "process3");
-               fprintf(stderr, "[%s] > Opening pipe\n", "process2");
+               fprintf(stderr, "[%s] > Opening pipe\n", "process3");
                read_descriptor = open(read_pipe, O_RDONLY);
        }
 }
@@ -63,8 +60,8 @@ int main(void) {
        if (signal(SIGTERM, sig_handler) == SIG_ERR) {
                fprintf(stderr, "can't catch SIGTERM\n");
        }
-       if (signal(SIGINT, sig_handler) == SIG_ERR) {
-               fprintf(stderr, "can't catch SIGINT\n");
+       if (signal(SIGTSTP, sig_handler) == SIG_ERR) {
+               fprintf(stderr, "can't catch SIGTSTP\n");
        }
        if (signal(SIGCONT, sig_handler) == SIG_ERR) {
                fprintf(stderr, "can't catch SIGCONT\n");