简体   繁体   English

在Windows中查找Node.js服务器的进程ID

[英]Finding process id of a Node.js server in Windows

To find a process id of a node.js server in unix, we use below code: 要在unix中查找node.js服务器的进程ID,我们使用以下代码:

if (process.getgid) {
   console.log('Current gid: ' + process.getgid());
}

So I get output as 1888 in *nix OS, but when I execute same in Windows OS, I am getting output as undefined also as per node.js docs they have explicitly mentioned this method won't work in windows. 因此我在* nix OS中输出为1888 ,但是当我在Windows操作系统中执行相同的操作时,我的输出也是undefined因为每个node.js文档他们已明确提到此方法在Windows中不起作用。

So my question, is there anyway I can get process id in windows os? 所以我的问题是,无论如何我可以在Windows操作系统中获取进程ID吗? I tried to execute taskkill /f /im node.exe but it kills all node processes, but I want to kill only particualr process. 我试图执行taskkill /f /im node.exe但它会杀死所有节点进程,但我想只杀死特定进程。 Is there anyway to achieve this? 反正有没有实现这个目标?

on windows process.pid works for me. 在windows上, process.pid对我process.pid

regarding the docs, getgid is not returning the Process ID, rather the group identity of the process , to get the process id use pid 关于文档, getgid不返回进程ID,而是返回进程的组标识 ,以获取进程id使用pid

To kill the process use: 要杀死进程使用:

taskkill /f /pid processID

Use tasklist to find the correct ID... 使用任务列表查找正确的ID ...

You can then use taskkill when you sort through the correct id to kill that particular one. 然后,当您对正确的ID进行排序以杀死该特定ID时,您可以使用taskkill。 Not entirely sure if it'd work in node. 不完全确定它是否在节点中工作。 But it's something that'd work on the CMD. 但这对CMD起作用。

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

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