3

i use child process in my node app, most of the times everything works good, but sometimes i get exit code 12.

this is how i initiate process

        const childProcess = require('child_process');
        const child = childProcess.fork('Path to file');
        child.send({data})

handling on exit:

 child.on('exit', (code) => {
 child.kill(); 
 console.log (code)
)}

and i get "12",

any ideas? i dont know how to debug child process

Thanks!

BB_KING
  • 145
  • 2
  • 13
  • The child program can set the process's exit code to whatever value it wants. There's no universal meaning for the value. (Often the value 0 means "success" and non-zero values indicate different types of failure, but that's just a convention. A program does not have to follow that convention.) To figure out what the value 12 means in this case you'll have to read the documentation for this specific child program, or read the source, or ask the developers. – ottomeister Jun 11 '18 at 01:17

2 Answers2

10

I actually ran into the same issue. I think the exit code relates to the node's child process exit code. In Node.js documentation, there is a mention of all of the exit codes. Here is the link - https://nodejs.org/api/process.html#process_exit_codes. There is a mention of a possible solution using clusters. The link to the Github issue is this.

Here is the solution. The exit code 12 is an error that can be generated because of no debug port defined for your child process. You have to add --inspect flag to the child process to get rid of the error. Follow this link to add the argument. Here is my code screenshot. I hope it helps.

Happy coding.

Kunal Nain
  • 116
  • 2
  • 6
1

Just add {execArgv: ['--harmony']}

const child_process = require('child_process');

let child = child_process.fork('./child.js', 'first_child', {execArgv: ['--harmony']});
vijay
  • 10,276
  • 11
  • 64
  • 79