简体   繁体   中英

Killing process in node.js

I have a piece of code that I really like, but there is a bug in one of the modules. This, sometimes, causes a runaway process that hogs up to 99% of the CPU time.

Now, I found a piece of code posted by someone with the same issue in github:

exec = require('child_process').exec

terminatePH = (ph, cb) ->
    ph.exit()
    exec 'kill '+ph.process.pid, cb

The problem is I do not understand this code. I think it is Coffeescript (or something along those lines) but it certainly is not Node.js that I am using.

Can someone please enlighten me? My main issue is that the 'exec' part, the one that does the killing, is AFTER 'ph.exit()'. Will this be executed properly?

Any ideas?

Yes you're right, this code was writen in CoffeeScript.

As a javascript:

var exec = require('child_process').exec()

var terminatePH = function (ph, cb) {
   ph.exit();
   return exec('kill ' + ph.process.pid, cb);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM