Is there any equivalent `fork` in Golang?

171 views
Skip to first unread message

Jiajun Huang

unread,
Mar 7, 2018, 6:37:18 AM3/7/18
to golang-nuts
hello, is there any replacement for `fork` syscall in Golang?

I've found:

- exec.Command
- syscall.ForkExec

but `exec.Command` can only execute a out side command.

syscall.ForkExec is needless, because what I need is `fork` only.

just like the C-way, fork, and return pid, then I entry different function. Is there any solution?

Lutz Horn

unread,
Mar 7, 2018, 6:40:58 AM3/7/18
to golan...@googlegroups.com
> hello, is there any replacement for `fork` syscall in Golang?

See https://stackoverflow.com/a/28371586

> Note that fork() has been invented at the time when no threads were
> used at all, and a process had always had just a single thread of
> execution in it, and hence forking it was safe. With Go, the situation
> is radically different as it heavily uses OS-level threads to power its
> goroutine scheduling.

Regards

Lutz

gansteed

unread,
Mar 7, 2018, 6:50:10 AM3/7/18
to Lutz Horn, golan...@googlegroups.com
thanks

Lutz Horn <lutz...@posteo.de>于2018年3月7日周三 下午7:40写道:
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/0Th87sxlzOE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages