From: Rafał Długołęcki Date: Sat, 21 Jun 2014 05:51:01 +0000 (+0200) Subject: Replace SIGINT with SIGTSTP. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=621bd5704dfeeccf51097ba255010bd37054972c;p=wsti_so.git Replace SIGINT with SIGTSTP. --- diff --git a/src/process1.c b/src/process1.c index fbee7c9..aa27e8c 100644 --- a/src/process1.c +++ b/src/process1.c @@ -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"); diff --git a/src/process2.c b/src/process2.c index 75dacfd..87871e7 100644 --- a/src/process2.c +++ b/src/process2.c @@ -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"); diff --git a/src/process3.c b/src/process3.c index de70b8d..b75f903 100644 --- a/src/process3.c +++ b/src/process3.c @@ -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");