Trying not to kill linux process started in Go

I need to control databases and others messaging servers from Go-managed html site. I can launch the processes, but they end with the go-managed html server. Is there a way that go-launched processes continue living after the go routine that launched them ends (or crash) ?

What do you mean go-launched processes? Are you referring to a goroutine? Like the go html site (server) launching a goroutine that controls the database and another goroutine to handle messaging? I’m not sure if that’s possible since all routines ends when the main goroutine that created them ends, afaik.

But if you are referring to external programs launched, I thinks there is exec.Start() for that.

What you could to is to turn those goroutines into separate programs/services and enable them to receive messages/instructions from your (html) web server.

Yes this is exactly what I mean. To be more specific, I have a go program that simulate the data transferred by an IoT device. I would like to be able to command this program from an html page (that is, the go server running). It works well with exex.Start(), but my IoT simulator stops if the html server stops, and this is not nice. What I need is a procedure that create a new process and then let it go completely.
I tried with “StartProcess”, but it seems that every process created by a go program is actually a child process of the main program

you need to release the child process.

    cmd := exec.Command(binary, args...)
cmd.Dir = cwd

err = cmd.Start()
if err != nil {
	return err
}
err = cmd.Process.Release()

Thank you it works! The Process.Release() is a well hidden function or am I dreaming? I think it is exactly what I needed, thanks again

Correction: I could not make the cmd.Process.Release work.
What works is: in the go code, start children process with nohup &. Do launch my server from terminal and NOT from Goland IDE. It seems the IDE makes go programs run under a parent ___go_build_main_go process that takes care to terminate all children authoritatively. the nohup and ampersand are there, if I understand well, to detach the process from the terminal application. I will test it under a linux with no xorg running. Normally when a process is orphaned it is not killed but take a close pid as a parent, under normal circumpstances init, so the question should not even had been raised :slight_smile: