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
9
votes
1 answer

Node.js pass handle of response object handle to child process

I have an http server and a forked child process. I want the parent to receive requests and pass to forked process using worker.send. and the worker should be able to process and send the response back to the requester using the same response…
Salman
  • 9,299
  • 6
  • 40
  • 73
9
votes
2 answers

Reattaching to spawned process via nodejs

I am creating a small proprietary game server manager in Node.js; currently it runs the game by spawning via child_process: var server = spawn(cmd, args, { cwd: 'something' }); So long as the manager continues to run I can pipe commands and deal…
Chad
  • 19,219
  • 4
  • 50
  • 73
8
votes
0 answers

node child_process exec : run as administrator

in node, thanks to child_process , I manage to launch visual studio . var vsExe = '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\\IDE\\devenv.exe"'; let commande = `${vsExe}`; var exec =…
Pipo
  • 5,170
  • 7
  • 33
  • 66
8
votes
2 answers

How do I pass a single string with multiple arguments to std::process::Command?

Rust's std::process::Command type demands that process arguments be passed in individually via .arg("-arg1").arg("-arg2") or as a vector of strings via .args(&["-arg1", "-arg2"]). How do you split a string into a vector that can be passed as…
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
8
votes
1 answer

childProcess.spawn fails when `env` is specified

I'm using Node's childProcess module to try and run NPM tasks. When I do the following, everything works file: const child = childProcess.spawn('npm', ['run', taskName], { cwd: `${parentPath}/${projectId}`, }); However, I need to provide…
Joshua Comeau
  • 2,594
  • 24
  • 25
8
votes
1 answer

Can't spawn `gcloud app deploy` from a Node.js script on Windows

I'm building an Electron application (Node.js) which needs to spawn gcloud app deploy from the application with realtime feedback (stdin/stdout/stderr). I rapidly switched from child_process to execa because I had some issues on Mac OS X with the…
8
votes
3 answers

How to use a pdflatex child process to get a PDF as a stream in Node.js?

Here are my files: . ├── app.js ├── res.cls └── res.tex And here is the relevant contents of my app.js file: const { spawn } = require('child_process') const latex = spawn('pdflatex', ['res.tex']) Running this code successfully creates a res.pdf…
Saad
  • 49,729
  • 21
  • 73
  • 112
8
votes
1 answer

how to kill a process group using Python subprocess

I am trying to do the equivalent of the following using Python subprocess: >cat /var/log/dmesg | festival --tts & [1] 30875 >kill -9 -30875 Note that I am killing the process group (as indicated by the negative sign prepending the process ID…
d3pd
  • 7,935
  • 24
  • 76
  • 127
8
votes
2 answers

How do I ensure that a spawned Child process is killed if my app panics?

I'm writing a small test that starts a daemon process and tests it e.g: let server = Command::new("target/debug/server").spawn(); // do some tests server.kill(); The typical way to fail a test is to panic. Unfortunately this means that kill()…
j16r
  • 189
  • 2
  • 7
8
votes
0 answers

How to apply a colour when piping stdout from a child process?

I'm using chalk to colour the output from from my command-line node application. Normally like this: console.log(chalk.red(error)); However, I need to pipe stdout from a child process, and colour this output too: var child =…
mtmacdonald
  • 14,216
  • 19
  • 63
  • 99
8
votes
2 answers

ssh with nodejs child_process, command not found on server

I'm attempting to run a simple ssh command, via nodejs child_process. when i run the command via nodejs code, it fails saying the command that i sent to the server was not found. when i run the same command just copy & pasting to my terminal window,…
Derick Bailey
  • 72,004
  • 22
  • 206
  • 219
8
votes
4 answers

how do I make node child_process exec continuously

How to exec continuously? e.g. ls after cd? I tried exec = require('child_process').exec; exec('cd ~/', function(){ exec('ls'), function(err, stdout, stderr){ console.log(stdout); // this logs current dir but not ~/'s } …
dotslashlu
  • 3,361
  • 4
  • 29
  • 56
8
votes
1 answer

Ways to implement CPU bound tasks in nodejs

I am using nodejs for a web server which decodes the GET params and returns data in some encoded format. The decode/encode are done using the crypto module of nodejs, which seems to be synchronous. While the time taken to serve a single request is…
mdprasadeng
  • 143
  • 1
  • 8
8
votes
1 answer

How to read from a child_process line by line in Node.js?

I am trying to make a Node.js script to analyse disk usage. For this, I shell out to du, but I am having trouble figuring out how to read the output from the child process line by line. Here's what I've tried so far: var spawn =…
mikl
  • 23,749
  • 20
  • 68
  • 89
7
votes
1 answer

capture pid of terminated background process using trap in bash

I'm writing a bash script that spawns a number of background processes. I'd like to be notified whenever a process terminates; and I would like to know the pid of the terminated process. I have looked at using wait, such that the pids of each…
jbeard4
  • 12,664
  • 4
  • 57
  • 67