After suspending child process with SIGTSTP, shell not responding

后端 未结 4 1675
误落风尘
误落风尘 2020-12-20 19:23

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

I think my signal handler is correct, and my child process is suspending, b

4条回答
  •  感动是毒
    2020-12-20 20:20

    tcsetpgrp is to specify what is the foreground job. When your shell spawns a job in foreground (without &), it should create a new process group and make that the foreground job (of the controlling terminal, not whatever's on STDIN). Then, upon pressing CTRL-Z, that job will get the TSTP. It's the terminal that suspends the job, not your shell. Your shell shouldn't trap TSTP or send TSTP to anyone.

    It should just wait() for the job it has spawned and detect when it has been stopped (and claim back the foreground group and mark the job as suspended internally). Your fg command would make the job's pgid the foreground process group again and send a SIGCONT to it and wait for it again, while bg would just send the SIGCONT

提交回复
热议问题