I have a program that will spawn child processes on certain events. I had initially used Command::new("exe").spawn()?;, which seemed to do what I wanted; but then I noticed that you should call .wait() on the Child. This works fine if the child exits quickly, but for a longer-running process, it blocks the main program until it exits.
I could use another thread, but I would need to join the thread at the end of the function, which would still block the main thread (or I could just make the whole program multi-threaded, but I thought there might be an easier way). Is there a simpler way to spawn a process and forget about it without refactoring my whole program to use multiple threads?
I don't need to have support for anything other than Linux.
Yea, I guess that would work, but if the a child process that the spawned thread created was still alive when the main thread exited, the process would be terminated, right?
OTOH the program will probably be run as a fairly long-lived daemon, so that shouldn't be much of a problem in reality.
You could have a secondary thread dedicated to spawning commands (and eventually another thread to wait on those). You would send the commands to that thread via a queue.