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

process.kill() doesn't kill the real command while using shell option #46865

Closed
leobgm opened this issue Feb 27, 2023 · 4 comments
Closed

process.kill() doesn't kill the real command while using shell option #46865

leobgm opened this issue Feb 27, 2023 · 4 comments

Comments

@leobgm
Copy link

leobgm commented Feb 27, 2023

Version

16.14.0

Platform

UNIX Ubuntu 20.04.3 TLS

Subsystem

No response

What steps will reproduce the bug?

I'm not sure it could be reproduced in all cases. I'm usin spawn with shell: true to run a command.

How often does it reproduce? Is there a required condition?

For me, it's a constant behavior. Always the same.

What is the expected behavior?

Expected behavior is the real process to be killed with process.kill(). But only sh wrapper is killed. Real command keeps running.

What do you see instead?

I monitored my processes. When I run a command using spawn and shell: true, it runs two processes in OS. One is the sh wrapper, and another one in my real command. With two separate PIDs.

When I use process.kill(), sh is killed. But real command keeps running (not killed).

Additional information

Anything we get from a process instance such as process.pid or process.kill() is related to sh wrapper. Not real running command.

@Linkgoron
Copy link
Member

Linkgoron commented Feb 27, 2023

I think that this is a duplicate of #37518

@leobgm
Copy link
Author

leobgm commented Feb 27, 2023

Yes seems like the same problem. So is it fixed now? What version should I use?

And also, is there a way to get the PID of real command running (not sh)? Because I might need to solve it with my current using version of NodeJS.

@meixg
Copy link
Member

meixg commented Feb 28, 2023

Also a duplicate of #2098. It is more like a Linux pitfall than a Node.js bug.
And based on the discussion in https://github.com/nodejs/node/pull/6052/files, there seems no good solution about this.

@bnoordhuis
Copy link
Member

That's fundamentally how Unices work, it's not specific to node. If you use { detached: true }, you can send a signal to the process group with process.kill(-pid).

Closing, working as intended (by the inventors of UNIX.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants