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
20
votes
3 answers

Display running child process' output in nodejs (windows)

For example sake, I'm running the most basic webServer in node (I'm using windows) with the following code (named server.js): var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type':…
mayorbyrne
  • 495
  • 1
  • 5
  • 16
19
votes
1 answer

Node.js / child_process throwing E2BIG

I have a fairly simple C++ program which only takes one argument that is a Base64 encoded string. I can call the program. I am now trying to call this program using Node.js' child_process.spawn(), but it is throwing an "E2BIG" error when I pass in…
Jonathan Smith
  • 2,390
  • 1
  • 34
  • 60
18
votes
4 answers

Terminating zombie child processes forked from socket server

Disclaimer I am well aware that PHP might not have been the best choice in this case for a socket server. Please refrain from suggesting different languages/platforms - believe me - I've heard it from all directions. Working in a Unix…
Lix
  • 47,311
  • 12
  • 103
  • 131
18
votes
3 answers

Node child processes: how to intercept signals like SIGINT

In my Node app, I'm hooking on the SIGINT signal in order to gracefully stop (using pm2, but this is not relevant here). My app also execs/spawns a couple of child processes. I am able to hook on SIGINT to intercept it and perform graceful stop,…
julien_c
  • 4,942
  • 5
  • 39
  • 54
18
votes
2 answers

Node Child Process Exec Command Failed with error code 1

I am trying to execute some line using node js child process and getting error. Following is my code: let cmd : string = "code " + PROJECTS[value]; exec(cmd, function callback(error, stdout, stderr) { console.log("started console app"); }); ERROR…
Shan Khan
  • 9,667
  • 17
  • 61
  • 111
18
votes
1 answer

nodejs child_process.spawnSync or child_process.spawn wrapped in yieldable generator which returns output

since a while i am trying to reach something that doesn't work out for me so far. With nodejs, i like to run a interactive sh-command and work with the sh-command output after the command has exited. i like to write a yieldable generator-function…
divramod
  • 1,454
  • 2
  • 20
  • 35
18
votes
2 answers

How can I parse a string into appropriate arguments for child_process.spawn?

I want to be able to take a command string, for example: some/script --option="Quoted Option" -d --another-option 'Quoted Argument' And parse it into something that I can send to child_process.spawn: spawn("some/script", ["--option=\"Quoted…
Michael Bleigh
  • 25,334
  • 2
  • 79
  • 85
17
votes
3 answers

Any drawbacks of having all functions async?

The newer node js has async await, which are really cool because it makes the code look better. I was wondering if it's a good idea to make every class method async, even if it doesn't need to return a promise? In my use case I actually sort of need…
Alex
  • 66,732
  • 177
  • 439
  • 641
16
votes
2 answers

Unable to trap SIGINT signal in a background shell

I am unable to trap a signal when running in a child / background process. Here is my simple bash script: #!/bin/bash echo "in child" trap "got_signal" SIGINT function got_signal { echo "trapped" exit 0 } while [ true ]; do sleep…
Matthieu
  • 16,103
  • 10
  • 59
  • 86
16
votes
1 answer

CPU-bound process blocks worker pool while using Child Process in NestJS HTTP server

Node version: v10.13.0 I'm trying a very simple test on NodeJS request concurrency involving heavy CPU-calculation. I understand NodeJS is not the best tool for CPU-bound processes, and that a child process should not be spawned systematically, but…
Bob
  • 1,495
  • 1
  • 19
  • 24
16
votes
1 answer

How to get the output of a spawned child_process in Node.JS?

First of all, I'm a complete noob and started using Node.JS yesterday (it was also my first time using Linux in years) so please be nice and explicit I'm currently making a Node.JS program which has to, among other things, launch shell commands…
Runj
  • 185
  • 1
  • 2
  • 11
16
votes
5 answers

How to debug child Node.JS process in Visual Studio Code?

How to debug child Node.JS process in VS Code? Here is the example of the code that I'm trying to debug: var spawn = require('child_process').spawn; var scriptPath = './child-script.js'; var runner_ = spawn('node', [scriptPath]);
vicneanschi
  • 468
  • 1
  • 4
  • 13
16
votes
1 answer

Node.JS child processes being killed when parent dies

I am using child_process.spawn() to start a script from my Node.JS application running on Ubuntu. As far as I know, standard forked or spawned *nix processes don't generally die when the parent dies, but when spawning processes from Node.JS, they…
JHH
  • 8,567
  • 8
  • 47
  • 91
16
votes
3 answers

Node child process spawn stdout returning as null

I'm writing a Yeoman generator and using child_process.spawn() (via yeoman's spawnCommand() - see https://github.com/yeoman/generator/blob/master/lib/actions/spawn_command.js) My code looks like this: var list = this.spawnCommand('npm', ['list',…
jinglesthula
  • 4,446
  • 4
  • 45
  • 79
16
votes
1 answer

Write to spawned process stdin nodejs?

I have a script that I want to run from another one. The problem is that the child script (process) needs an user input before it continues. var child = spawn('script'); child.stdin.setEncoding('utf8'); child.stdout.on('data', function (data) { …
simo
  • 15,078
  • 7
  • 45
  • 59