Questions tagged [child-process]

For questions regarding child-process

In Unix, a child process is typically created as a copy of the parent, using the fork system call. The child process can then overlay itself with a different program (using exec) as required.

Each process may create many child processes but will have at most one parent process; if a process does not have a parent this usually indicates that it was created directly by the kernel.

The inter communication between a child process and a parent process can be done through normal communication schemes such as pipes, sockets, message queues, shared memories.

When a child process terminates, some information is returned to the parent process. When a child process terminates before the parent has called wait, the kernel retains some information about the process, such as its exit status, to enable its parent to call wait later

2233 questions
12
votes
1 answer

node.js run function in child process?

I have a node.js application that receives a file, via a web request and then will apply a conversion process to this file. Since the task is long running this needs to run separate to the main thread. At the moment I have just called the necessary…
Andre M
  • 6,649
  • 7
  • 52
  • 93
12
votes
2 answers

node.js: How to spawn detached child in foreground and exit

According to the docs for child_process.spawn I would expect to be able to run a child process in the foreground and allow the node process itself to exit like so: handoff-exec.js: 'use strict'; var spawn = require('child_process').spawn; // this…
coolaj86
  • 74,004
  • 20
  • 105
  • 125
12
votes
2 answers

Nodejs child_process spawn get command ran

For clarify purposes I want to see the exact command Node.js runs versus the shell/cli. Unfortunately I can't seem to find out how... https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options The returned…
2778
  • 814
  • 1
  • 11
  • 32
12
votes
1 answer

Nodejs child_process spawn custom stdio

I would like to use custom stream to handle child_process.spawn stdio. For example const cp = require('child_process'); const process = require('process'); const stream = require('stream'); var customStream = new…
Mr Br
  • 3,831
  • 1
  • 20
  • 24
12
votes
1 answer

Passing node flags/args to child process

If we fork a child_process in Node, how can we pass node parameters to the child_process? https://nodejs.org/api/child_process.html Specifically I would like to spawn ~20 processes, and would like to limit the memory usage of each by using…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
12
votes
3 answers

Killing a bash script does not kill child processes

I have written a test script which runs another script to start the server to test. When the tests have completed a SIGKILL message is sent to the server process, however when running the test script again the server throws a EADDRINUSE error (I‘m…
Calebmer
  • 2,972
  • 6
  • 29
  • 36
12
votes
1 answer

NodeJS child process stdout are all numbers

I'm writing some node.js scripts to kick off a child process. Code snippet is as below. var spawn = require('child_process').spawn; var child = spawn ('node', ['script.js']) child.stdout.on('data', function (data) { …
Lee
  • 2,874
  • 3
  • 27
  • 51
12
votes
1 answer

nodejs exec command failing with no useful error message

This is the code to execute cp.exec("cc -Wall /tmp/test.c -o /tmp/test", function(e, stdout, stderr) { if (e) { var errorstr = "Compilation failed with the following error"+ e.message.toString() …
Shrikrishna Holla
  • 256
  • 1
  • 2
  • 11
12
votes
1 answer

node.js spawned process sticks around if script is killed

Is it possible to make sure that processes spawned with node.js child_process will be killed when the parent is killed? Here's an example script var spawn = require('child_process').spawn; var log_tail = spawn("tail", ["-f",…
case nelson
  • 3,537
  • 3
  • 30
  • 37
11
votes
1 answer

Do I have to close inherited handle later owned by child process?

Microsoft played safe here. In their article, "Creating a Child Process with Redirected Input and Output", they are saying: The remaining open handles are cleaned up when this process terminates. To avoid resource leaks in a larger application,…
GSerg
  • 76,472
  • 17
  • 159
  • 346
11
votes
1 answer

copy-webpack-plugin configuration issue

Within an electron.js app I'm trying to call and execute a python script from node.js based on the these indicatins: https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback import { execFile } from…
Raphael10
  • 2,508
  • 7
  • 22
  • 50
11
votes
4 answers

how to turn Child_process.spawn's "Promise" syntax to "async/await" syntax

So I have this code and I'm trying to understand the async/await syntax in full depth. The below is the Promise version of the code: function callToolsPromise(req) { return new Promise((resolve, reject) => { let pipshell = 'pipenv'; …
tinnick
  • 316
  • 1
  • 2
  • 15
11
votes
5 answers

Creating a child process WITHOUT fork()

Is there a way to start a child process without fork(), using execvp() exclusively?
gonidelis
  • 885
  • 10
  • 32
11
votes
1 answer

How can I make child_process.spawn return a Promise in my TypeScript module?

I'm trying to write a little module that uses child_process.spawn to clone a git repo and return a Promise but it fails on me. When I'm using spawnSync it works. Here is the sync code that works. import {spawnSync} from 'child_process'; export…
fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41
11
votes
2 answers

sanitize user input for child_process.exec command

I'm writing a CLI using node and I've arrived at the part where I take user input and append it to a string that is the command for the child_process.exec function. const CURL_CHILD = exec('npm view --json ' + process.argv[2] + ... I am trying to…
Kraken
  • 5,043
  • 3
  • 25
  • 46