pty.js icon indicating copy to clipboard operation
pty.js copied to clipboard

zombie process either by process.kill or pty.destroy

Open hayeah opened this issue 11 years ago • 5 comments

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

hayeah avatar Jan 10 '14 03:01 hayeah

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

hhuuggoo avatar Feb 19 '14 07:02 hhuuggoo

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

chjj avatar Feb 21 '14 03:02 chjj

Any update on this ?

moul avatar Oct 06 '14 09:10 moul

+1

EloB avatar Oct 15 '14 13:10 EloB

:+1: :)

howardroark avatar Jun 15 '15 21:06 howardroark