child-process

node.js run function in child process?

☆樱花仙子☆ 提交于 2019-12-22 05:18:08
问题 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 code via a setTimeout() call. To isolate the main application from the conversion process I would like to move it out into a child process, since it is long running and I would like to isolate the main code from the work being done (am I worrying

Nodejs child_process spawn custom stdio

。_饼干妹妹 提交于 2019-12-22 04:09:48
问题 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 stream.Stream(); customStream.on('data', function (chunk) { console.log(chunk); }); cp.spawn('ls', [], { stdio: [null, customStream, process.stderr] }); I get error Incorrect value for stdio stream . There is documentation for child_process.spawn https://nodejs.org/api/child_process

Stdout of Node.js child_process exec is cut short

和自甴很熟 提交于 2019-12-22 03:30:28
问题 In Node.js I'm using the exec command of the child_process module to call an algorithm in Java that returns a large amount of text to standard out which I then parse and use. I'm able to capture it mostly, but when it exceeds a certain number of lines, the content is cutoff. exec("sh target/bin/solver "+fields.dimx+" "+fields.dimy, function(error, stdout, stderr){ //do stuff with stdout } I've tried using setTimeouts and callbacks but haven't succeeded but I do feel this is occurring because

It is possible to get the progress of a spawned process from nodejs?

别等时光非礼了梦想. 提交于 2019-12-21 22:50:03
问题 I'm spawning npm install -g create-react-app from a js script. I want to know if it's possible to get the progress of the installation using spawn . const npmExecutable = /^win/.test(process.platform) ? "npm.cmd" : "npm"; const npm = spawn(npmExecutable, ["install", "-g", "create-react-app"]); I have read this question about using: npm.on("message", data => { console.log(`A message: ${data}`); }); but it does not show anything. There is a related question, about knowing the progress of a

How to pass a key file when spawning an ssh command from node.js?

a 夏天 提交于 2019-12-21 17:37:58
问题 This works from my local terminal: ssh -i ~/.ec2/mykey.pem ubuntu@ec2-yada-yada.amazonaws.com ls Of course it does. But when I try the same using node.js' child_process.spawn command it complains that the key does not exist / can't be accessed. // child process var childProcess = require('child_process').spawn; // spawn the slave using slaveId as the key slaves[slaveId] = childProcess('ssh', [ '-i /mykey.pem', 'ubuntu@ec2-yada.amazonaws.com', 'ls' ]) Result: stderr: Warning: Identity file

Detach child process from parent

随声附和 提交于 2019-12-21 17:16:46
问题 When a child process forked from a parent dies, it still exists to some extent and is left in a zombie state, until it is reaped from a wait() call. Is is possible to detach this parent-child relationship and have the children be automatically reaped? Maybe orphan off the child to init, or something? Possible use case: Creating a lot of fire-and-forget processes in a long-lived program, without "holding" on to an increasing list of zombie PIDs that cannot be recycled by the OS. 回答1: Per the

How to pass function/callback to child process in Node.js?

早过忘川 提交于 2019-12-21 09:33:08
问题 Let's say I have a parent.js containing a method named parent var childProcess = require('child_process'); var options = { someData: {a:1, b:2, c:3}, asyncFn: function (data, callback) { /*do other async stuff here*/ } }; function Parent(options, callback) { var child = childProcess.fork('./child'); child.send({ method: method, options: options }); child.on('message', function(data){ callback(data,err, data,result); child.kill(); }); } Meanwhile in child.js process.on('message', function(data

how are concurrent requests handled in PHP (using - threads, thread pool or child processes)

柔情痞子 提交于 2019-12-21 03:11:09
问题 I understand that PHP supports handling multiple concurrent connections and depending on server it can be configured as mentioned in this answer How does server manages multiple connections does it forks a child process for each request or does it handle using threads or does it handles using a thread pool? The linked answer says a process is forked and then the author in comment says threads or process, which makes it confusing, if requests are served using child-processes, threads or thread

Trap signal in child background process

淺唱寂寞╮ 提交于 2019-12-20 19:41:57
问题 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 2 done When running this and later do kill -SIGINT (pid) Everything works as expected, it prints 'trapped' and exits. Now, if I start the same script from a parent script like this : #!/bin/bash echo "starting the child" ./child.sh & Then the child does not trap the

Stream stdout from child process to browser via expressjs

南楼画角 提交于 2019-12-20 12:38:43
问题 We have an app built using nodejs , express and child_process.spawn . One requirement is that we need to spawn a process at runtime and capture it's output and present it to the user. We have that working. However, we need to figure out a way to stream the output instead of waiting until the child process exists. We've looked around and couldn't find any clear cut examples and were wondering if anyone here had any ideas? Everything is working. We just don't care for the user experience of