英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论