如何获得过程清单 [英] how to get the list of process

查看:73
本文介绍了如何获得过程清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩弄节点,并将其安装在我的机器上.现在,我想获取机器上正在运行的进程的列表,以便查看Apache是​​否正在运行,MySQL是否已启动等?我怎样才能做到这一点?我的js文件中只有非常基本的代码.我什至不知道从哪里开始.

I am playing around with node and just installed it on my machine. Now I want to get a list of processes running on my machine so I can see whether Apache is running, MySQL is started, etc? How can I do that? I just have very basic code in my js file. I don't even know where to begin on this.

这是我的代码:

var http = require('http');
http.createServer(function(request, response){
    response.writeHead(200);
    response.write("Hello world");
    console.log('Listenning on port 1339');
    response.end();
}).listen(8080);

推荐答案

据我所知,还没有一个模块可以执行此跨平台操作.您可以使用子流程API来启动提供所需数据的工具.对于Windows,只需启动内置的任务列表过程即可.

As far as I know there isn't a module (yet) to do this cross-platform. You can use the child process API to launch tools that will give the data you want. For Windows, just launch the built-in tasklist process.

var exec = require('child_process').exec;
exec('tasklist', function(err, stdout, stderr) {
  // stdout is a string containing the output of the command.
  // parse it and look for the apache and mysql processes.
});

这篇关于如何获得过程清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆