OP here -> I'm going to put together some test apps - toss them on GitHub and make sure I actually know what I'm talking about :)
On Friday, March 1, 2024 at 7:57:15 PM UTC-7 Ian Lance Taylor wrote: > On Fri, Mar 1, 2024 at 6:17 PM Robert Engels <ren...@ix.netcom.com> wrote: > > > > The could be calling fork() as in the system call - which copies all > file descriptors but I didn’t think Go processes could fork. > > > > Seems you would need to remap stdin and stdout in the fork to do > anything useful. > > > > This sounds very PHP - what goes around comes around. > > Good point, I am assuming that the OP is using the os/exec package to > start up a new copy of the process. > > A simple fork without an exec can't work in Go, or in any > multi-threaded program. > > Ian > > > > > On Mar 1, 2024, at 8:01 PM, Ian Lance Taylor <ia...@golang.org> wrote: > > > > > > On Fri, Mar 1, 2024 at 5:57 PM Jeff Stein <jeff...@gmail.com> wrote: > > >> > > >> I'm struggling to understand if I'm able to do something. > > >> > > >> > > >> In my very odd use case we are writing a websever that handles > connections via a forked process. > > >> > > >> I have a listener process that listens for TCP connections. > > >> > > >> So each net.Conn that comes in we pull off its file descriptor: > > >> > > >> fd, err := conn.(*net.TCPConn).File() > > >> > > >> duplicate that file descriptor and then fork off a process passing in > that file descriptor. > > >> > > >> In my forked handler I'll reconstruct the HTTP connection and "do > stuff". > > >> > > >> The concern I'm having is that it appears when I fork a process I > inherit all of the parent file descriptors so if I have say 5 incoming > connections and then I fork my child process technically could write to a > different connection. > > >> > > >> I've played around with the various options: > > >> > > >> cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: false,} > > >> > > >> and using cmd.ExtraFiles > > >> > > >> No matter what I do I seem unable to limit the sub process to ONLY > using the specific File Descriptor I want it to have access to. > > >> > > >> I believe this is doable in C - but I'm not sure if I can do this in > GoLang as-is without mods . > > > > > > What you are describing shouldn't happen. A child process should only > > > get the file descriptors explicitly passed via the os/exec.Cmd fields > > > Stdin, Stdout, Stderr, and ExtraFiles. So tell us more: OS and > > > version of Go, and what is showing you that all file descriptors are > > > being passed down to the child. > > > > > > Ian > > > > > > -- > > > You received this message because you are subscribed to the Google > Groups "golang-nuts" group. > > > To unsubscribe from this group and stop receiving emails from it, send > an email to golang-nuts...@googlegroups.com. > > > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUb27YBCyE52QisHLyB9XPPpEycMxt4FrFJogGsFMiemQ%40mail.gmail.com > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/fd650788-d500-4d44-8664-70ce57b917f3n%40googlegroups.com.