duanchen9594
2016-08-05 15:28
浏览 13
已采纳

终止“运行”进程会导致什么幻影进程?

I have been running a server with:

go run server.go &

When I am done with the process, this requires me to kill the process. The way I have been doing this is with kill PID of the go run process.

However, I've noticed my server appears connected still. Investigating further it seems that there are other processes go is starting which appear to "keep alive" my server:

$ps aux | grep go
username   70481   0.0  0.0 573416816   5228   ??  S     3:15PM   0:00.63 /var/folders/wf/89r2567s5hv48lj1g9l65mbw0000gp/T/go-build062422854/command-line-arguments/_obj/exe/server
username   70472   0.0  0.0 573407408   7720   ??  S     3:15PM   0:00.80 go run server.go

When I kill this associated process, too, I see that my connection is released as expected.

Is there a better way to "really" kill a golang process than kill PID? Or is there a reason why there are these phantom processes?

I have resorted to killing both but this seems... strange.

$ go version
go version go1.5.4 darwin/amd64
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsn46282 2016-08-05 15:35
    已采纳

    The one you're calling the "phantom process" is your server, which is why killing it kills your server. The other is the "go run" utility itself, which is compiling your code and then running the resulting executable.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题