Skip to content

child_process.spawn sh not killable#2098

@paulpflug

Description

@paulpflug

Comming from here:
darkguy2008/parallelshell#22

(btw: Usecase for #1009)

Everytime I need to spawn a process I do it like this

if(process.platform==='win32'){sh='cmd';shFlag='/c';}else{sh='sh';shFlag='-c';}varchild=spawn(sh,[shFlag,cmd],{cwd: process.cwd,env: process.env,stdio: ['pipe',process.stdout,process.stderr]})

The problem: child is unkillable on unix.
Example in coffee-script:

spawn=require("child_process").spawnchild=spawn"sh", ["-c", "node -e 'setTimeout(function(){},10000);'"] child.on"close", process.exitchild.kill() child.kill("SIGINT") child.kill("SIGTERM") child.kill("SIGHUP") spawn"sh",["-c","kill -TERM "+child.pid] spawn"sh",["-c","kill -INT "+child.pid] spawn"sh",["-c","kill -HUP "+child.pid]

(on windows it works fine with sh replaced by cmd)
Even when I exit the process with process.exit(), the child stays alive.

Workaround I found:

spawn=require("child_process").spawnchild=spawn"sh", ["-c", "node -e 'setTimeout(function(){},10000);'"], detached:truechild.on"close", process.exitspawn"sh",["-c","kill -INT -"+child.pid]

Killing by pgid works, by pid works not. Sending ^C from console works also, I assume it uses pgid always.

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions