Why does os.StartProcess in Go set the child's process group id equal to the child pid

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

Why does os.StartProcess in Go set the child's process group id equal to the child pid

问题

golang库函数os.StartProcess()在子进程fork之后调用setpgid(0,0)

它在"linux"和"bsd"配置上执行此操作,源代码在这里:
http://golang.org/src/pkg/syscall/exec_bsd.go?h=SYS_SETPGID#L105
http://golang.org/src/pkg/syscall/exec_linux.go?h=SYS_SETPGID#L117

我之前注意到,OSX Foundation库的NSTask - (void)launch方法也做了同样的事情(未记录)。当时我觉得这是个麻烦,因为它使得进程树的管理更加困难。

这些库自动执行此操作的好处是什么?

英文:

The golang library function os.StartProcess() calls setpgid(0,0) in the child process after forking.

It does this on the "linux" and "bsd" configurations, sources here:
http://golang.org/src/pkg/syscall/exec_bsd.go?h=SYS_SETPGID#L105
http://golang.org/src/pkg/syscall/exec_linux.go?h=SYS_SETPGID#L117

I noticed in the past that the OSX Foundation library NSTask - (void)launch method does the same thing (undocumented). At that time it seemed like an annoyance as it makes it harder to manage trees of processes.

What is the benefit of these libraries doing this automatically?

答案1

得分: 1

简短回答是它不会改变组,除非attr.Sys.Setpgid为true。这是为了与系统的API保持功能一致。在所有操作系统上甚至都不是一个选项。

英文:

The short answer is that it doesn't. It only changes the group if attr.Sys.Setpgid is true. This is to have feature parity with the system's API. It is not even an option on all OSes

huangapple
  • 本文由 发表于 2014年10月14日 13:20:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/26353150.html
匿名

发表评论

匿名网友

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

确定