Add SIGSTOP in SIGTSTP to properly stop the process.
[wsti_so.git] / src / process2.c
index 75dacfde993ab2fa3f29357ac1fa335896dd827a..49081737183fa6d1fc98faf725daed73a78d09bc 100644 (file)
@@ -28,25 +28,23 @@ 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);
+               raise (SIGSTOP);
        }
        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 +83,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");