mirror of
https://github.com/bvanroll/rpiRadio.git
synced 2025-08-30 12:32:47 +00:00
Initial Commit
This commit is contained in:
41
ProjectNow/NodeServer/node_modules/ps-tree/.appveyor.yml
generated
vendored
Normal file
41
ProjectNow/NodeServer/node_modules/ps-tree/.appveyor.yml
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# http://www.appveyor.com/docs/appveyor-yml
|
||||
|
||||
# Fix line endings in Windows. (runs before repo cloning)
|
||||
init:
|
||||
- git config --global core.autocrlf true
|
||||
|
||||
# Test against these versions of Node.js.
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "0.12"
|
||||
- nodejs_version: "4.2"
|
||||
- nodejs_version: "6.2"
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- nodejs_version: 0.10
|
||||
- nodejs_version: 0.12
|
||||
|
||||
# Install scripts. (runs after repo cloning)
|
||||
install:
|
||||
- git rev-parse HEAD
|
||||
# Get the latest stable version of Node 0.STABLE.latest
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
# Typical npm stuff.
|
||||
- md C:\nc
|
||||
- npm config set cache C:\nc
|
||||
- npm version
|
||||
- npm install
|
||||
|
||||
# Post-install test scripts.
|
||||
test_script:
|
||||
# Output useful info for debugging.
|
||||
- npm version
|
||||
- cmd: npm test
|
||||
|
||||
# Don't actually build.
|
||||
build: off
|
||||
|
||||
# Set build version format here instead of in the admin panel.
|
||||
version: "{build}"
|
28
ProjectNow/NodeServer/node_modules/ps-tree/.npmignore
generated
vendored
Normal file
28
ProjectNow/NodeServer/node_modules/ps-tree/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
# Commenting this out is preferred by some people, see
|
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
|
||||
node_modules
|
||||
|
||||
# Users Environment Variables
|
||||
.lock-wscript
|
22
ProjectNow/NodeServer/node_modules/ps-tree/.travis.yml
generated
vendored
Normal file
22
ProjectNow/NodeServer/node_modules/ps-tree/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "4.4"
|
||||
- "6.2"
|
||||
os:
|
||||
- linux
|
||||
- centos
|
||||
- macosx
|
||||
|
||||
before_install:
|
||||
- travis_retry npm install -g npm@2.14.2
|
||||
- travis_retry npm install
|
||||
|
||||
script:
|
||||
- npm test
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- node_js: "0.10"
|
||||
- node_js: "0.12"
|
21
ProjectNow/NodeServer/node_modules/ps-tree/LICENSE
generated
vendored
Normal file
21
ProjectNow/NodeServer/node_modules/ps-tree/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Domenic Tarr, Charlie Robbins & the Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
83
ProjectNow/NodeServer/node_modules/ps-tree/README.md
generated
vendored
Normal file
83
ProjectNow/NodeServer/node_modules/ps-tree/README.md
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
# ps-tree
|
||||
|
||||
[](https://travis-ci.org/indexzero/ps-tree)
|
||||
[](https://codeclimate.com/github/indexzero/ps-tree)
|
||||
[](https://codeclimate.com/github/indexzero/ps-tree)
|
||||
[](http://badge.fury.io/js/ps-tree)
|
||||
[![Node.js Version][node-version-image]][node-version-url]
|
||||
[](https://david-dm.org/indexzero/ps-tree)
|
||||
[node-version-image]: https://img.shields.io/node/v/listdirs.svg?style=flat
|
||||
[node-version-url]: http://nodejs.org/download/
|
||||
|
||||
Sometimes you cannot kill child processes like you would expect, this a feature of UNIX.
|
||||
|
||||
>in UNIX, a process may terminate by using the exit call, and it's parent process may wait for that event by using the wait system call. the wait system call returns the process identifier of a terminated child, so that the parent tell which of the possibly many children has terminated. If the parent terminates, however, all it's children have assigned as their new parent the init process. Thus, the children still have a parent to collect their status and execution statistics.
|
||||
> (from "operating system concepts")
|
||||
|
||||
Solution: use `ps-tree` to get all processes that a `child_process` may have started, so that they may all be terminated.
|
||||
|
||||
``` js
|
||||
var cp = require('child_process'),
|
||||
psTree = require('ps-tree');
|
||||
|
||||
var child = cp.exec("node -e 'while (true);'", function () {...});
|
||||
|
||||
// This will not actually kill the child it will kill the `sh` process.
|
||||
child.kill();
|
||||
```
|
||||
|
||||
wtf? it's because exec actually works like this:
|
||||
|
||||
``` js
|
||||
function exec (cmd, cb) {
|
||||
spawn('sh', ['-c', cmd]);
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
`sh` starts parses the command string and starts processes, and waits for them to terminate, but `exec` returns a process object with the pid of the `sh` process.
|
||||
However, since it is in `wait` mode killing it does not kill the children.
|
||||
|
||||
Use `ps-tree` like this:
|
||||
|
||||
``` js
|
||||
var cp = require('child_process'),
|
||||
psTree = require('ps-tree');
|
||||
|
||||
var child = cp.exec("node -e 'while (true);'", function () { /*...*/ });
|
||||
|
||||
psTree(child.pid, function (err, children) {
|
||||
cp.spawn('kill', ['-9'].concat(children.map(function (p) { return p.PID })));
|
||||
});
|
||||
```
|
||||
|
||||
If you prefer to run **psTree** from the command line, use: `node ./bin/ps-tree.js`
|
||||
|
||||
## Cross Platform support
|
||||
|
||||
|
||||
The `ps-tree` module behaves differently on *nix vs. Windows by spawning different programs and parsing their output. This is based on `process.platform` and not on checking to see if a `ps` compatible program exists on the system.
|
||||
|
||||
#### *nix
|
||||
|
||||
1. " <defunct> " need to be striped
|
||||
```bash
|
||||
$ ps -A -o comm,ppid,pid,stat
|
||||
COMMAND PPID PID STAT
|
||||
bbsd 2899 16958 Ss
|
||||
watch <defunct> 1914 16964 Z
|
||||
ps 20688 16965 R+
|
||||
```
|
||||
|
||||
### Windows
|
||||
1. `wmic PROCESS WHERE ParentProcessId=4604 GET Name,ParentProcessId,ProcessId,Status)`
|
||||
2. The order of head columns is fixed
|
||||
```shell
|
||||
> wmic PROCESS GET Name,ProcessId,ParentProcessId,Status
|
||||
Name ParentProcessId ProcessId Status
|
||||
System Idle Process 0 0
|
||||
System 0 4
|
||||
smss.exe 4 228
|
||||
```
|
||||
|
||||
### LICENSE: MIT
|
16
ProjectNow/NodeServer/node_modules/ps-tree/bin/ps-tree.js
generated
vendored
Normal file
16
ProjectNow/NodeServer/node_modules/ps-tree/bin/ps-tree.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
//
|
||||
// Change the default parent PID if running
|
||||
// under Windows.
|
||||
//
|
||||
var ppid = 1;
|
||||
if (process.platform === 'win32') {
|
||||
ppid = 0;
|
||||
}
|
||||
|
||||
require('../')(process.argv[2] || ppid, function (err, data) {
|
||||
console.log(data);
|
||||
});
|
118
ProjectNow/NodeServer/node_modules/ps-tree/index.js
generated
vendored
Executable file
118
ProjectNow/NodeServer/node_modules/ps-tree/index.js
generated
vendored
Executable file
@@ -0,0 +1,118 @@
|
||||
'use strict';
|
||||
|
||||
var spawn = require('child_process').spawn,
|
||||
es = require('event-stream');
|
||||
|
||||
module.exports = function childrenOfPid(pid, callback) {
|
||||
var headers = null;
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
throw new Error('childrenOfPid(pid, callback) expects callback');
|
||||
}
|
||||
|
||||
if (typeof pid === 'number') {
|
||||
pid = pid.toString();
|
||||
}
|
||||
|
||||
//
|
||||
// The `ps-tree` module behaves differently on *nix vs. Windows
|
||||
// by spawning different programs and parsing their output.
|
||||
//
|
||||
// Linux:
|
||||
// 1. " <defunct> " need to be striped
|
||||
// ```bash
|
||||
// $ ps -A -o comm,ppid,pid,stat
|
||||
// COMMAND PPID PID STAT
|
||||
// bbsd 2899 16958 Ss
|
||||
// watch <defunct> 1914 16964 Z
|
||||
// ps 20688 16965 R+
|
||||
// ```
|
||||
//
|
||||
// Win32:
|
||||
// 1. wmic PROCESS WHERE ParentProcessId=4604 GET Name,ParentProcessId,ProcessId,Status)
|
||||
// 2. The order of head columns is fixed
|
||||
// ```shell
|
||||
// > wmic PROCESS GET Name,ProcessId,ParentProcessId,Status
|
||||
// Name ParentProcessId ProcessId Status
|
||||
// System Idle Process 0 0
|
||||
// System 0 4
|
||||
// smss.exe 4 228
|
||||
// ```
|
||||
|
||||
var processLister;
|
||||
if (process.platform === 'win32') {
|
||||
// See also: https://github.com/nodejs/node-v0.x-archive/issues/2318
|
||||
processLister = spawn('wmic.exe', ['PROCESS', 'GET', 'Name,ProcessId,ParentProcessId,Status']);
|
||||
} else {
|
||||
processLister = spawn('ps', ['-A', '-o', 'ppid,pid,stat,comm']);
|
||||
}
|
||||
|
||||
es.connect(
|
||||
// spawn('ps', ['-A', '-o', 'ppid,pid,stat,comm']).stdout,
|
||||
processLister.stdout,
|
||||
es.split(),
|
||||
es.map(function (line, cb) { //this could parse alot of unix command output
|
||||
var columns = line.trim().split(/\s+/);
|
||||
if (!headers) {
|
||||
headers = columns;
|
||||
|
||||
//
|
||||
// Rename Win32 header name, to as same as the linux, for compatible.
|
||||
//
|
||||
headers = headers.map(normalizeHeader);
|
||||
return cb();
|
||||
}
|
||||
|
||||
var row = {};
|
||||
// For each header
|
||||
var h = headers.slice();
|
||||
while (h.length) {
|
||||
row[h.shift()] = h.length ? columns.shift() : columns.join(' ');
|
||||
}
|
||||
|
||||
return cb(null, row);
|
||||
}),
|
||||
es.writeArray(function (err, ps) {
|
||||
var parents = [pid],
|
||||
children = [];
|
||||
|
||||
ps.forEach(function (proc) {
|
||||
if (parents.indexOf(proc.PPID) !== -1) {
|
||||
parents.push(proc.PID)
|
||||
children.push(proc)
|
||||
}
|
||||
});
|
||||
|
||||
callback(null, children);
|
||||
})
|
||||
).on('error', callback)
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the given header `str` from the Windows
|
||||
* title to the *nix title.
|
||||
*
|
||||
* @param {string} str Header string to normalize
|
||||
*/
|
||||
function normalizeHeader(str) {
|
||||
if (process.platform !== 'win32') {
|
||||
return str;
|
||||
}
|
||||
|
||||
switch (str) {
|
||||
case 'Name':
|
||||
return 'COMMAND';
|
||||
break;
|
||||
case 'ParentProcessId':
|
||||
return 'PPID';
|
||||
break;
|
||||
case 'ProcessId':
|
||||
return 'PID';
|
||||
break;
|
||||
case 'Status':
|
||||
return 'STAT';
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown process listing header: ' + str);
|
||||
}
|
||||
}
|
79
ProjectNow/NodeServer/node_modules/ps-tree/package.json
generated
vendored
Normal file
79
ProjectNow/NodeServer/node_modules/ps-tree/package.json
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"_from": "ps-tree@^1.1.0",
|
||||
"_id": "ps-tree@1.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-tCGyQUDWID8e08dplrRCewjowBQ=",
|
||||
"_location": "/ps-tree",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "ps-tree@^1.1.0",
|
||||
"name": "ps-tree",
|
||||
"escapedName": "ps-tree",
|
||||
"rawSpec": "^1.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/pstree.remy"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ps-tree/-/ps-tree-1.1.0.tgz",
|
||||
"_shasum": "b421b24140d6203f1ed3c76996b4427b08e8c014",
|
||||
"_spec": "ps-tree@^1.1.0",
|
||||
"_where": "/home/beppe/Documents/Python/proj/1718PROJrpiRadio/NodeServer/node_modules/pstree.remy",
|
||||
"author": {
|
||||
"name": "Charlie Robbins",
|
||||
"email": "charlie.robbins@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/indexzero/ps-tree/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Zhuohuan LI",
|
||||
"email": "zixia@zixia.net",
|
||||
"url": "https://github.com/zixia"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"event-stream": "~3.3.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Get all children of a pid",
|
||||
"devDependencies": {
|
||||
"chalk": "^1.0.0",
|
||||
"codeclimate-test-reporter": "0.0.4",
|
||||
"cross-env": "^1.0.8",
|
||||
"istanbul": "^0.3.20",
|
||||
"pre-commit": "0.0.9",
|
||||
"precommit": "^1.1.5",
|
||||
"tape": "^3.0.3",
|
||||
"tree-kill": "^1.1.0"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
},
|
||||
"homepage": "http://github.com/indexzero/ps-tree",
|
||||
"license": "MIT",
|
||||
"name": "ps-tree",
|
||||
"pre-commit": [
|
||||
"coverage",
|
||||
"codeclimate"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/indexzero/ps-tree.git"
|
||||
},
|
||||
"scripts": {
|
||||
"_comment": "https://github.com/gotwarlost/istanbul#usage-on-windows",
|
||||
"codeclimate": "cross-env CODECLIMATE_REPO_TOKEN=84436b4f13c70ace9c62e7f04928bf23c234eb212c0232d39d7fb1535beb2da5 codeclimate < coverage/lcov.info",
|
||||
"coverage": "npm test && istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100",
|
||||
"test": "istanbul cover node_modules/tape/bin/tape test/test.js test/direct.js"
|
||||
},
|
||||
"version": "1.1.0"
|
||||
}
|
20
ProjectNow/NodeServer/node_modules/ps-tree/test/direct.js
generated
vendored
Normal file
20
ProjectNow/NodeServer/node_modules/ps-tree/test/direct.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
var test = require('tape');
|
||||
var chalk = require('chalk');
|
||||
var cp = require('child_process');
|
||||
|
||||
var red = chalk.red,
|
||||
green = chalk.green,
|
||||
cyan = chalk.cyan;
|
||||
|
||||
test(cyan('Directly Execute bin/ps-tree.js'), function (t) {
|
||||
var first = cp.exec('node -v', function (error, stdout, stderr) {});
|
||||
var child = cp.exec('node ./bin/ps-tree.js', function (error, data) {
|
||||
// console.log('data: ' + data.length);
|
||||
if (error !== null) {
|
||||
console.log(red('exec error: ' + error));
|
||||
}
|
||||
});
|
||||
|
||||
t.true(child.pid, green('✓ Called ./bin/ps-tree.js directly. worked as expected'));
|
||||
t.end();
|
||||
});
|
7
ProjectNow/NodeServer/node_modules/ps-tree/test/exec/child.js
generated
vendored
Normal file
7
ProjectNow/NodeServer/node_modules/ps-tree/test/exec/child.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// does nothing child process
|
||||
console.log("Child process.id: " + process.pid);
|
||||
console.log(" - - - - - - - - - - - - - - - - - - - - - - - ");
|
||||
|
||||
setTimeout(function () {
|
||||
/* Does nothing, but prevents exit */
|
||||
}, 1000);
|
18
ProjectNow/NodeServer/node_modules/ps-tree/test/exec/parent.js
generated
vendored
Normal file
18
ProjectNow/NodeServer/node_modules/ps-tree/test/exec/parent.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
var cp = require('child_process');
|
||||
var chalk = require('chalk');
|
||||
var red = chalk.red
|
||||
var green = chalk.green
|
||||
var cyan = chalk.cyan;
|
||||
var count = 0;
|
||||
|
||||
while(count < 10) {
|
||||
var child = cp.exec("node ./test/exec/child.js", function(error, stdout, stderr) {
|
||||
console.log('stdout: ' + stdout);
|
||||
console.log(red('stderr: ' + stderr));
|
||||
if (error !== null) {
|
||||
console.log(red('exec error: ' + error));
|
||||
}
|
||||
})
|
||||
|
||||
console.log("child pid: %s | count: %s", child.pid, ++count);
|
||||
}
|
70
ProjectNow/NodeServer/node_modules/ps-tree/test/test.js
generated
vendored
Normal file
70
ProjectNow/NodeServer/node_modules/ps-tree/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
var path = require('path');
|
||||
var test = require('tape');
|
||||
var chalk = require('chalk');
|
||||
var cp = require('child_process');
|
||||
var treeKill = require('tree-kill');
|
||||
var psTree = require('../');
|
||||
|
||||
var red = chalk.red,
|
||||
green = chalk.green,
|
||||
cyan = chalk.cyan;
|
||||
|
||||
var scripts = {
|
||||
parent: path.join(__dirname, 'exec', 'parent.js'),
|
||||
child: path.join(__dirname, 'exec', 'child.js')
|
||||
};
|
||||
|
||||
test(cyan('Spawn a Parent process which has a Two Child Processes'), function (t) {
|
||||
var parent = cp.exec('node ' + scripts.parent, function (error, stdout, stderr) {});
|
||||
|
||||
setTimeout(function () {
|
||||
psTree(parent.pid, function (err, children) {
|
||||
if (err) { console.log(err); }
|
||||
console.log(red('Children: '), children, '\n');
|
||||
t.true(children.length > 0, green('✓ There are ' + children.length + ' active child processes'));
|
||||
treeKill(parent.pid);
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
psTree(parent.pid, function (err, children) {
|
||||
if (err) { console.log(err); }
|
||||
// console.log('Children: ', children, '\n');
|
||||
// console.log(' ')
|
||||
t.equal(children.length, 0, green('✓ No more active child processes (we killed them)'));
|
||||
t.end();
|
||||
});
|
||||
}, 2000); // give psTree time to kill the processes
|
||||
}, 500); // give the child process time to spawn
|
||||
// need more time on a slow(or heavy load server). maybe promise.then is better instead of the timeout
|
||||
});
|
||||
|
||||
test(cyan('FORCE ERROR by calling psTree without supplying a Callback'), function (t) {
|
||||
var errmsg = 'Error: childrenOfPid(pid, callback) expects callback'
|
||||
// Attempt to call psTree without a callback
|
||||
try { psTree(1234); }
|
||||
catch (e) {
|
||||
t.equal(e.toString(), errmsg, green('✓ Fails when no callback supplied (as expected)'))
|
||||
}
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test(cyan('Spawn a Child Process and psTree with a String as pid'), function (t) {
|
||||
var child = cp.exec('node ' + scripts.child, function(error, stdout, stderr) {});
|
||||
setTimeout(function(){
|
||||
psTree(child.pid.toString(), function (err, children) {
|
||||
if (err) { console.log(err); }
|
||||
// cp.spawn('kill', ['-9'].concat(children.map(function (p) { return p.PID })))
|
||||
treeKill(child.pid);
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
psTree(child.pid.toString(), function (err, children) {
|
||||
if (err) { console.log(err); }
|
||||
t.equal(children.length, 0, green('✓ No more active child processes'));
|
||||
t.end();
|
||||
});
|
||||
}, 1000); // give psTree time to kill the processes
|
||||
}, 200); // give the child process time to spawn
|
||||
});
|
Reference in New Issue
Block a user