// Copyright (c) 2013 Perforce Software. All rights reserved. var _ = require("underscore"); var child_process = require("child_process"); function ProcessUtil(grunt) { this.grunt = grunt; } _.extend(ProcessUtil.prototype, { // Lists processes by executing an underlying command and parsing the output // into JSON. // // If error is true, the other parameters are stdout, and stderr. // // Otherwise, the callback returns an array of objects. // // Current fields returned: // - pid // - user // - command // list: function(callback) { child_process.exec("ps -ax -o pid,user,command", function(error, stdout, stderr) { if (error) { callback(error, stdout, stderr); } var procs = []; _.each(_.rest(stdout.split("\n")), function(line) { var toks = line.trim().split(/\s+/); if (toks.length >= 3) { procs.push({ pid: parseInt(toks[0], 10), user: toks[1], cmd: toks[2] }); } }); callback(null, procs); }); } }); module.exports = ProcessUtil;
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 10513 | tjuricek |
A basic experiment with using the C++ API in Go May not work completely. I haven't messed with this in over a year. The Go tools may have come a long ways as well, and we may be able to automate things more directly in the typical toolkit then having to use node. |