Permalink
Browse files

child_process: rename child_process to exec

Fixes #1549.
  • Loading branch information...
1 parent 49ba55b commit d79a08c3f3ae7836c22d08f598bb248fa0e5e954 @koichik committed Dec 3, 2011
Showing with 886 additions and 751 deletions.
  1. +9 −9 Makefile
  2. +0 −1 benchmark/http_simple.js
  3. +2 −2 benchmark/process_loop.js
  4. +2 −2 benchmark/run.js
  5. +1 −1 benchmark/startup.js
  6. +1 −1 benchmark/throughput.js
  7. +1 −1 doc/api/_toc.markdown
  8. +1 −1 doc/api/all.markdown
  9. +3 −3 doc/api/cluster.markdown
  10. +62 −51 doc/api/{child_processes.markdown → exec.markdown}
  11. +1 −1 doc/index.html
  12. +1 −1 lib/_debugger.js
  13. +18 −479 lib/child_process.js
  14. +1 −1 lib/cluster.js
  15. +500 −0 lib/exec.js
  16. +1 −1 lib/net.js
  17. +1 −1 lib/repl.js
  18. +2 −2 lib/util.js
  19. +1 −0 node.gyp
  20. +2 −2 src/node.js
  21. +1 −1 test/common.js
  22. 0 test/fixtures/{child-process-spawn-node.js → exec-spawn-node.js}
  23. +2 −2 test/fixtures/{child_process_should_emit_error.js → exec_should_emit_error.js}
  24. +1 −1 test/pummel/{test-child-process-spawn-loop.js → test-exec-spawn-loop.js}
  25. +7 −7 test/pummel/test-exec.js
  26. +2 −2 test/pummel/test-keep-alive.js
  27. +1 −1 test/pummel/test-regress-GH-814.js
  28. +1 −1 test/pummel/test-regress-GH-814_2.js
  29. +1 −1 test/pummel/test-regress-GH-892.js
  30. +0 −8 test/simple/test-child-process-customfd-bounded.js
  31. +0 −26 test/simple/test-child-process-fork.js
  32. +0 −55 test/simple/test-child-process-fork2.js
  33. +8 −8 test/simple/test-cli-eval.js
  34. +1 −1 test/simple/test-cluster-kill-workers.js
  35. +1 −1 test/simple/test-debugger-client.js
  36. +1 −1 test/simple/test-debugger-repl-utf8.js
  37. +1 −1 test/simple/test-debugger-repl.js
  38. +2 −2 test/simple/test-error-reporting.js
  39. +1 −1 test/simple/test-eval-require.js
  40. +2 −2 test/simple/test-eval.js
  41. +1 −1 test/simple/{test-child-process-buffering.js → test-exec-buffering.js}
  42. +29 −0 test/simple/test-exec-customfd-bounded.js
  43. +1 −1 test/simple/{test-child-process-cwd.js → test-exec-cwd.js}
  44. +1 −1 test/simple/{test-child-process-double-pipe.js → test-exec-double-pipe.js}
  45. +1 −1 test/simple/{test-child-process-env.js → test-exec-env.js}
  46. +2 −2 test/simple/{test-child-process-exit-code.js → test-exec-exit-code.js}
  47. +47 −0 test/simple/test-exec-fork.js
  48. +76 −0 test/simple/test-exec-fork2.js
  49. +1 −1 test/simple/{test-child-process-ipc.js → test-exec-ipc.js}
  50. +1 −1 test/simple/{test-child-process-kill.js → test-exec-kill.js}
  51. +2 −2 test/simple/test-exec-max-buffer.js
  52. +2 −2 test/simple/{test-child-process-set-blocking.js → test-exec-set-blocking.js}
  53. +2 −2 test/simple/{test-child-process-exec-cwd.js → test-exec-shell-cwd.js}
  54. +3 −3 test/simple/{test-child-process-exec-env.js → test-exec-shell-env.js}
  55. +1 −1 test/simple/{test-child-process-stdin.js → test-exec-stdin.js}
  56. +1 −1 test/simple/{test-child-process-stdout-flush.js → test-exec-stdout-flush.js}
  57. +3 −2 test/simple/test-fs-realpath.js
  58. +2 −2 test/simple/test-fs-symlink.js
  59. +2 −2 test/simple/test-http-304.js
  60. +4 −4 test/simple/test-http-curl-chunk-problem.js
  61. +2 −2 test/simple/test-http-full-response.js
  62. +2 −2 test/simple/test-https-foafssl.js
  63. +3 −3 test/simple/test-https-simple.js
  64. +5 −5 test/simple/test-init.js
  65. +2 −2 test/simple/test-pipe-file-to-http.js
  66. +2 −2 test/simple/test-pipe-head.js
  67. +1 −1 test/simple/test-process-env.js
  68. +1 −1 test/simple/test-process-kill-null.js
  69. +23 −2 test/simple/test-regress-GH-1697.js
  70. +2 −2 test/simple/test-regress-GH-1726.js
  71. +1 −1 test/simple/test-regress-GH-1899.js
  72. +2 −2 test/simple/test-setproctitle.js
  73. +1 −1 test/simple/test-sigint-infinite-loop.js
  74. +1 −1 test/simple/test-signal-unregister.js
  75. +2 −2 test/simple/test-stdin-from-file.js
  76. +2 −2 test/simple/test-stdout-to-file.js
  77. +1 −1 test/simple/test-tls-ext-key-usage.js
  78. +1 −1 test/simple/test-tls-peer-certificate.js
  79. +1 −1 test/simple/test-tls-securepair-client.js
  80. +1 −1 test/simple/test-tls-securepair-server.js
  81. +1 −1 test/simple/test-tls-server-verify.js
  82. +2 −2 test/simple/test-tls-session-cache.js
  83. +2 −2 test/simple/test-tls-set-ciphers.js
View
@@ -227,15 +227,15 @@ UVTEST += simple/test-tls-securepair-server
#UVTEST += simple/test-tls-server-verify # broken
UVTEST += simple/test-tls-set-encoding
-# child_process
-UVTEST += simple/test-child-process-exit-code
-UVTEST += simple/test-child-process-buffering
-UVTEST += simple/test-child-process-exec-cwd
-UVTEST += simple/test-child-process-cwd
-UVTEST += simple/test-child-process-env
-UVTEST += simple/test-child-process-stdin
-UVTEST += simple/test-child-process-ipc
-UVTEST += simple/test-child-process-deprecated-api
+# exec
+UVTEST += simple/test-exec-exit-code
+UVTEST += simple/test-exec-buffering
+UVTEST += simple/test-exec-exec-cwd
+UVTEST += simple/test-exec-cwd
+UVTEST += simple/test-exec-env
+UVTEST += simple/test-exec-stdin
+UVTEST += simple/test-exec-ipc
+UVTEST += simple/test-exec-deprecated-api
test-uv: all
View
@@ -1,5 +1,4 @@
path = require("path");
-exec = require("child_process").exec;
http = require("http");
port = parseInt(process.env.PORT || 8000);
@@ -1,10 +1,10 @@
var util = require("util"),
- childProcess = require("child_process");
+ exec = require("exec");
function next (i) {
if (i <= 0) return;
- var child = childProcess.spawn("echo", ["hello"]);
+ var child = exec.spawn("echo", ["hello"]);
child.stdout.addListener("data", function (chunk) {
util.print(chunk);
View
@@ -1,6 +1,6 @@
var path = require("path");
var util = require("util");
-var childProcess = require("child_process");
+var spawn = require("exec").spawn;
var benchmarks = [ "timers.js"
, "process_loop.js"
, "static_http_server.js"
@@ -10,7 +10,7 @@ var benchmarkDir = path.dirname(__filename);
function exec (script, callback) {
var start = new Date();
- var child = childProcess.spawn(process.argv[0], [path.join(benchmarkDir, script)]);
+ var child = spawn(process.argv[0], [path.join(benchmarkDir, script)]);
child.addListener("exit", function (code) {
var elapsed = new Date() - start;
callback(elapsed, code);
View
@@ -1,4 +1,4 @@
-var spawn = require('child_process').spawn,
+var spawn = require('exec').spawn,
path = require('path'),
emptyJsFile = path.join(__dirname, '../test/fixtures/semicolon.js'),
starts = 100,
View
@@ -1,4 +1,4 @@
-var fork = require('child_process').fork;
+var fork = require('exec').fork;
var net = require('net');
var buffer = new Buffer(1024 * 1024);
View
@@ -26,7 +26,7 @@
* [Readline](readline.html)
* [REPL](repl.html)
* [VM](vm.html)
-* [Child Processes](child_processes.html)
+* [Exec](exec.html)
* [Assertion Testing](assert.html)
* [TTY](tty.html)
* [ZLIB](zlib.html)
View
@@ -26,7 +26,7 @@
@include readline
@include repl
@include vm
-@include child_processes
+@include exec
@include assert
@include tty
@include zlib
View
@@ -34,10 +34,10 @@ Running node will now share port 8000 between the workers:
Worker 2438 online
Worker 2437 online
-The difference between `cluster.fork()` and `child_process.fork()` is simply
+The difference between `cluster.fork()` and `exec.fork()` is simply
that cluster allows TCP servers to be shared between workers. `cluster.fork`
-is implemented on top of `child_process.fork`. The message passing API that
-is available with `child_process.fork` is available with `cluster` as well.
+is implemented on top of `exec.fork`. The message passing API that
+is available with `exec.fork` is available with `cluster` as well.
As an example, here is a cluster which keeps count of the number of requests
in the master process via message passing:
@@ -1,19 +1,25 @@
-## Child Processes
+## Exec
+
+You can access this module with:
+
+ var exec = require('exec');
+
+### exec.ChildProcess
Node provides a tri-directional `popen(3)` facility through the `ChildProcess`
class.
It is possible to stream data through the child's `stdin`, `stdout`, and
`stderr` in a fully non-blocking way.
-To create a child process use `require('child_process').spawn()`.
+To create a child process use `require('exec').spawn()`.
Child processes always have three streams associated with them. `child.stdin`,
`child.stdout`, and `child.stderr`.
`ChildProcess` is an `EventEmitter`.
-### Event: 'exit'
+#### Event: 'exit'
`function (code, signal) {}`
@@ -24,36 +30,60 @@ of the signal, otherwise `null`.
See `waitpid(2)`.
-### child.stdin
+#### child.stdin
A `Writable Stream` that represents the child process's `stdin`.
Closing this stream via `end()` often causes the child process to terminate.
-### child.stdout
+#### child.stdout
A `Readable Stream` that represents the child process's `stdout`.
-### child.stderr
+#### child.stderr
A `Readable Stream` that represents the child process's `stderr`.
-### child.pid
+#### child.pid
The PID of the child process.
Example:
- var spawn = require('child_process').spawn,
+ var spawn = require('exec').spawn,
grep = spawn('grep', ['ssh']);
console.log('Spawned child pid: ' + grep.pid);
grep.stdin.end();
-### child_process.spawn(command, args=[], [options])
+#### child.kill(signal='SIGTERM')
+
+Send a signal to the child process. If no argument is given, the process will
+be sent `'SIGTERM'`. See `signal(7)` for a list of available signals.
+
+ var spawn = require('exec').spawn,
+ grep = spawn('grep', ['ssh']);
+
+ grep.on('exit', function (code, signal) {
+ console.log('child process terminated due to receipt of signal '+signal);
+ });
+
+ // send SIGHUP to process
+ grep.kill('SIGHUP');
+
+Note that while the function is called `kill`, the signal delivered to the child
+process may not actually kill it. `kill` really just sends a signal to a
+process.
+
+See `kill(2)`
+
+
+---
-Launches a new process with the given `command`, with command line arguments in `args`.
-If omitted, `args` defaults to an empty Array.
+### exec.spawn(command, args=[], [options])
+
+Launches a new process with the given `command`, with command line arguments
+in `args`. If omitted, `args` defaults to an empty Array.
The third argument is used to specify additional options, which defaults to:
@@ -62,15 +92,17 @@ The third argument is used to specify additional options, which defaults to:
setsid: false
}
-`cwd` allows you to specify the working directory from which the process is spawned.
-Use `env` to specify environment variables that will be visible to the new process.
+`cwd` allows you to specify the working directory from which the process is
+spawned. Use `env` to specify environment variables that will be visible to
+the new process.
`setsid`, if set true, will cause the subprocess to be run in a new session.
-Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the exit code:
+Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the exit
+code:
var util = require('util'),
- spawn = require('child_process').spawn,
+ spawn = require('exec').spawn,
ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', function (data) {
@@ -89,7 +121,7 @@ Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the exit cod
Example: A very elaborate way to run 'ps ax | grep ssh'
var util = require('util'),
- spawn = require('child_process').spawn,
+ spawn = require('exec').spawn,
ps = spawn('ps', ['ax']),
grep = spawn('grep', ['ssh']);
@@ -125,7 +157,7 @@ Example: A very elaborate way to run 'ps ax | grep ssh'
Example of checking for failed exec:
- var spawn = require('child_process').spawn,
+ var spawn = require('exec').spawn,
child = spawn('bad_command');
child.stderr.setEncoding('utf8');
@@ -151,17 +183,17 @@ There are several internal options. In particular `stdinStream`,
`stdoutStream`, `stderrStream`. They are for INTERNAL USE ONLY. As with all
undocumented APIs in Node, they should not be used.
-See also: `child_process.exec()`
+See also: `exec.shell()`
-### child_process.exec(command, [options], callback)
+### exec.shell(command, [options], callback)
Runs a command in a shell and buffers the output.
var util = require('util'),
- exec = require('child_process').exec,
+ shell = require('exec').shell,
child;
- child = exec('cat *.js bad_file | wc -l',
+ child = shell('cat *.js bad_file | wc -l',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
@@ -175,7 +207,8 @@ will be `null`. On error, `error` will be an instance of `Error` and `err.code`
will be the exit code of the child process, and `err.signal` will be set to the
signal that terminated the process.
-There is a second optional argument to specify several options. The default options are
+There is a second optional argument to specify several options. The default
+options are
{ encoding: 'utf8',
timeout: 0,
@@ -191,14 +224,14 @@ amount of data allowed on stdout or stderr - if this value is exceeded then
the child process is killed.
-### child_process.execFile(file, args, options, callback)
+### exec.file(file, args, options, callback)
-This is similar to `child_process.exec()` except it does not execute a
+This is similar to `exec.shell()` except it does not execute a
subshell but rather the specified file directly. This makes it slightly
-leaner than `child_process.exec`. It has the same options.
+leaner than `exec.shell`. It has the same options.
-### child_process.fork(modulePath, arguments, options)
+### exec.fork(modulePath, arguments, options)
This is a special case of the `spawn()` functionality for spawning Node
processes. In addition to having all the methods in a normal ChildProcess
@@ -208,9 +241,9 @@ are received by a `'message'` event on the child.
For example:
- var cp = require('child_process');
+ var exec = require('exec');
- var n = cp.fork(__dirname + '/sub.js');
+ var n = exec.fork(__dirname + '/sub.js');
n.on('message', function(m) {
console.log('PARENT got message:', m);
@@ -241,7 +274,7 @@ another process. Child will receive the handle as as second argument to the
`message` event. Here is an example of sending a handle:
var server = require('net').createServer();
- var child = require('child_process').fork(__dirname + '/child.js');
+ var child = require('exec').fork(__dirname + '/child.js');
// Open up the server object and send the handle.
server.listen(1337, function() {
child.send({ server: true }, server._handle);
@@ -256,25 +289,3 @@ processes:
server.listen(serverHandle);
}
});
-
-
-
-### child.kill(signal='SIGTERM')
-
-Send a signal to the child process. If no argument is given, the process will
-be sent `'SIGTERM'`. See `signal(7)` for a list of available signals.
-
- var spawn = require('child_process').spawn,
- grep = spawn('grep', ['ssh']);
-
- grep.on('exit', function (code, signal) {
- console.log('child process terminated due to receipt of signal '+signal);
- });
-
- // send SIGHUP to process
- grep.kill('SIGHUP');
-
-Note that while the function is called `kill`, the signal delivered to the child
-process may not actually kill it. `kill` really just sends a signal to a process.
-
-See `kill(2)`
View
@@ -187,7 +187,7 @@ <h2 id="about">About</h2>
necessary to scale programs to multi-core computers?
</i>
You can start new processes via
- <a href="http://nodejs.org/docs/latest/api/child_processes.html#child_process.fork"><code>child_process.fork()</code></a>
+ <a href="http://nodejs.org/docs/latest/api/exec.html#exec.fork"><code>exec.fork()</code></a>
these other processes will be scheduled in parallel.
For load balancing incoming connections across multiple processes
use <a href="http://nodejs.org/docs/latest/api/cluster.html">the
View
@@ -25,7 +25,7 @@ var util = require('util'),
vm = require('vm'),
repl = require('repl'),
inherits = util.inherits,
- spawn = require('child_process').spawn;
+ spawn = require('exec').spawn;
exports.start = function(argv, stdin, stdout) {
argv || (argv = process.argv.slice(2));
Oops, something went wrong.

0 comments on commit d79a08c

Please sign in to comment.