简体   繁体   English

在node.js中杀死进程

[英]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. 有时,这会导致进程失控,占用最多99%的CPU时间。

Now, I found a piece of code posted by someone with the same issue in github: 现在,我在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. 我认为它是Coffeescript(或类似的东西),但肯定不是我正在使用的Node.js。

Can someone please enlighten me? 有人可以启发我吗? My main issue is that the 'exec' part, the one that does the killing, is AFTER 'ph.exit()'. 我的主要问题是,“ exec”部分(执行杀死操作的部分)是在“ ph.exit()”之后。 Will this be executed properly? 会正确执行吗?

Any ideas? 有任何想法吗?

Yes you're right, this code was writen in CoffeeScript. 是的,您是对的,此代码是用CoffeeScript编写的。

As a javascript: 作为JavaScript:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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