Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't spawn child process

Tags:

node.js

I wrote a simple function that restarts/shuts down application. Restart doesn't work and i can't figure out why. Child process starts and then instantly shuts down. I tried catching errors from the child but there was no errors.

async function Shutdown(message,restart){
    if(message) console.log(message)

    await Logout()

    if(restart){
        let proc = childprocess.spawn(process.argv[0],process.argv.splice(1),{
            "detached": true,
        })
    }
    process.exit(0)
}
like image 758
EntityinArray Avatar asked Nov 16 '25 04:11

EntityinArray


1 Answers

From the documentation:

When using the detached option to start a long-running process, the process will not stay running in the background after the parent exits unless it is provided with a stdio configuration that is not connected to the parent.

So add stdio: 'ignore' or other methods to make child process stays alive

    let proc = childprocess.spawn(process.argv[0],process.argv.splice(1),{
          detached: true,
          stdio: 'ignore'
    })
   proc.unref();
like image 162
ufxmeng Avatar answered Nov 18 '25 20:11

ufxmeng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!