pty.js
pty.js copied to clipboard
zombie process either by process.kill or pty.destroy
This is the same problem as seen in https://github.com/chjj/pty.js/issues/8 (which is closed).
The following spawns a bash shell every 3 seconds, and destroys each one after 500ms. It leaves behind a bunch of zombie processes.
PTY = require("pty.js")
console.log "Process: #{process.pid}"
bash = ->
pty = PTY.spawn("bash",[],{
name: 'xterm-color'
cwd: process.cwd()
env: process.env
})
setTimeout (->
console.log "kill", pty.pid
# Both of the following leave zombie processes
# process.kill(pty.pid,"SIGTERM")
# process.kill(pty.pid,"SIGHUP")
pty.destroy()
), 500
setInterval (-> bash()), 3000
I think the problem is chjj/tty.js#111, basically you need to signal(SIGCHLD, SIG_INT), though I have no idea how to do that in node.js, process.on seems to require a function as the second parameter.
the following code works, however it seems to be a bit overkill
Terminal.prototype.kill = function(sig) {
try {
process.kill(this.pid, sig || 'SIGTERM');
waitpid(this.pid);
} catch(e) {
;
}
};
where waitpid is https://www.npmjs.org/package/waitpid
Yes, it's most likely due to the non-handling of SIGCHLD (which is what a zombie is: a child process whos exit never got read by waitpid after a sigchld). Adding our own SIGCHLD handler may conflict with the libuv SIGCHLD handler. It's still in the works. I may just merge it to master and use it for a while to see if there are any major problems.
SIGCHLD discussion: https://github.com/chjj/pty.js/pull/37
Any update on this ?
+1
:+1: :)