2

Possible Duplicate:
After suspending child process with SIGTSTP, shell not responding

I'm coding a basic shell in C, and I'm working on suspending a child process right now.

There should be two ways to do this.

  • One is when I type ps& into the input, with a & at the end, I call kill (pid, child_pid) and then I put the child's pid into an array for bg processes.

  • The second is when I press CTRL-Z on a currently running child process.

I think my signal handler is correct, and my child process is suspending, but after that, the terminal should return to the parent process and that's not happening.

The child is suspended, but my shell isn't registering any input or output anymore. tcsetpgrp() doesn't seem to be helping.

Here's 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 anyone tell me what I'm doing wrong?

Am I suspending my shell along with the child, and do I need to return stdin and stdout to the shell somehow? How would I do this?

Thanks!

Community
  • 1
  • 1
user1710304
  • 131
  • 1
  • 1
  • 4

0 Answers0