【发布时间】:2016-07-03 04:59:33
【问题描述】:
我在 Go 中有一个应用程序,它重新路由二进制文件的 STDIN 和 STDOUT,然后运行它们。简而言之,我正在做:
- create command object with the binary path (lets call the object command A)
- create command object with the binary path (calling it command B)
- set the stdout of command B to the stdin of Command A
- start command A
- start command B
我注意到,每当命令 B 的进程在命令 A 运行时退出时,它就会成为进程表中的僵尸进程。
这是一个例子:
commandA := exec.Command("samplebin")
commandB := exec.Command("sample2bin")
cmdAStdin := commandA.StdinPipe()
commandB.Stdout = cmdAStdin
commandA.Start()
commandB.Start()
如果 commandB 在 commandA 仍在运行时退出,为什么它会变成僵尸?我在 Ubuntu 14 上运行 Go 1.5。
【问题讨论】:
-
@chris-dodd 说的对,如果你只是不想要僵尸,你可以通过添加代码来忽略 SIGCHLD:
signal.Ignore(syscall.SIGCHLD)
标签: go process stdout stdin zombie-process