I'm building an Electron React App and one of its features is launching commands through child_process.spawn() calls. Currently, after I create said process (which most of the time is a simple yarn dev call), I cannot reference it later even after the handle call finishes, so I cannot destroy/kill said terminal process.
What I want is a way to handle said processes after the main thread handle call finishes and eventually refer to them later and kill them when necessary.
A good example would be: You launch the yarn dev command, Terminal Spawns and executes said commands and streams the output to a separate Terminal window. When necessary, the user clicks the "Kill" button and the whole yarn dev server shuts down.
I already tried with Redux, storing the whole ChildProcess (which was a bad idea because its not a serializable object). I also tried storing only the PIDs, but because they change and are not constant and consequentially I cannot kill the process through a kill <PID> call.
Edit: I tried by destroying the Terminal Window, but the process doesn't quit (aka the yarn server still runs).