I am coding a base shell in C and am currently working on pausing a child process.
I think that my signal handler is correct, and my child process is paused, but after that the terminal should return to the parent process and this will not happen.
The child is paused, but my shell no longer registers any inputs or outputs. tcsetpgrp () doesn't seem to help.
Here is my signal handler in my shell code for SIGTSTP:
void suspend(int sig) { pid_t pid; sigset_t mask; //mpid is the pgid of this shell. tcsetpgrp(STDIN_FILENO, mpid); tcsetpgrp(STDOUT_FILENO, mpid); sigemptyset(&mask); sigaddset(&mask, SIGTSTP); sigprocmask(SIG_UNBLOCK, &mask, NULL); signal(SIGTSTP, SIG_DFL); //active.pid is the pid of the child currently in the fg. if (active.pid != 0) { kill(active.pid, SIGTSTP); } else{ //if this code is being run in the child, child calls SIGTSTP on itself. pid = getpid(); if (pid != 0 && pid != mpid){ kill(pid, SIGTSTP); } } signal(SIGTSTP, suspend); }
Can someone tell me what I am doing wrong?
Am I pausing my shell along with a child, and do I need to somehow return stdin and stdout to the shell? How can I do it?
Thanks!
source share