发送 SIGTSTP 会暂停整个程序。

huangapple go评论86阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2015年7月30日 14:59:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/31717133.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定