Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Killing a child process returns exit code 0 instead of null #461

Open
SamVerschueren opened this issue Feb 24, 2021 · 2 comments
Open

Killing a child process returns exit code 0 instead of null #461

SamVerschueren opened this issue Feb 24, 2021 · 2 comments
Labels
enhancement help wanted Issues identified as good community contribution opportunities

Comments

@SamVerschueren
Copy link

SamVerschueren commented Feb 24, 2021

Environment details

  • OS: macOS Big Sur
  • OS version: 11.1
  • node-pty version: 0.10.0

Issue description

I'm testing some things out with node-pty and noticed a difference between how Node.js child_process handles on exit and how node-pty handles them.

I wrote a small example.

child.js

Just a small program that logs tick every second.

setInterval(() => {
    console.log('tick');
}, 1000);

cp.js

const cp = require('child_process');

const child = cp.spawn('node', ['child.js']);

child.on('exit', (exitCode, signal) => {
    console.log(exitCode, signal);
});

child.kill('SIGINT');

When I run this code, it logs

null SIGINT

So, the exitCode is null here because it was killed with a signal like SIGINT.

pty.js

const pty = require('node-pty');

const child = pty.spawn('node', ['./child.js']);

child.onExit(({exitCode, signal}) => {
    console.log(exitCode, signal);
});

child.kill('SIGINT');

Doing the same with node-pty however, gives me the following result

0 2

2 is the numeric value of SIGINT, but the exit code is 0 indicating that the process exited just fine.

The same goes if the child.js kills itself with process.exit(1) for instance, the signal with child_process is null, but for node-pty it's 0.

I'm wondering if node-pty wants to be on par with how child_process works or if this is expected behaviour?

Thanks for the package though, it's awesome :)!

@Tyriar
Copy link
Member

Tyriar commented May 25, 2021

I think we just pass along the code and signal, so not sure why this is happening:

node-pty/src/unix/pty.cc

Lines 505 to 508 in 6cf84b7

v8::Local<v8::Value> argv[] = {
Nan::New<v8::Integer>(baton->exit_code),
Nan::New<v8::Integer>(baton->signal_code),
};

const onexit = (code: number, signal: number): void => {

@Tyriar
Copy link
Member

Tyriar commented Oct 21, 2021

We should probably align here and hardcode null as the code when kill is called.

@Tyriar Tyriar added help wanted Issues identified as good community contribution opportunities enhancement labels Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

2 participants