英文:
Sending SIGTSTP suspends entire program
问题
我正在尝试向子进程发送SIGTSTP信号。我面临的问题是,向子进程发送SIGTSTP会暂停整个程序,调用者无法继续执行程序的其余部分。这是我的代码:
cmd := exec.Command("ping", "google.com")
stdout, _ := cmd.StdoutPipe()
cmd.Start()
io.Copy(os.Stdout, stdout)
cmd.Wait()
运行这段代码,我会在终端上打印出ping google.com
的输出。当我按下ctrl-z
时,输出会停止,但程序无法接收信号或执行其他操作,除非向子进程发送SIGCONT信号。我是否漏掉了什么?如何暂停子进程但继续执行调用者的程序?谢谢。
英文:
I'm trying to send a SIGTSTP signal to a child process. The problem I'm facing is that sending SIGTSTP to the child process halts my entire program and the caller is unable to proceed with execution of the rest of the program. Here's my code
cmd := exec.Command("ping", "google.com")
stdout, _ := cmd.StdoutPipe()
cmd.Start()
io.Copy(os.Stdout, stdout)
cmd.Wait()
Running this code, I get output from ping google.com
printed on the terminal. When I hit ctrl-z
, the output is stopped, but the program is not longer able to accept signals or do anything else unless SIGCONT is sent to the child process. Am I missing something? How do I suspend the child process but resume execution of the caller? Thanks.
答案1
得分: 2
Wait 等待命令退出。你的子进程并没有退出,只是暂停了,所以 Wait
不会返回。
英文:
Wait waits for the command to exit. Your child process isn't exiting, it's just paused, so Wait
doesn't return.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论