child-process

Passing node flags/args to child process

▼魔方 西西 提交于 2019-11-29 18:42:28
问题 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 --v8-options, but I can't find any examples of doing this - is this possible or do the child processes assume the same node parameters as the parent? the parent would be: node foo.js and the children would be node --some-flag=bar baz.js ... I am looking to

How to fetch the details from mongo db and send or store in object in nodejs Fork method

亡梦爱人 提交于 2019-11-29 17:28:57
Here I am using fork method to do some calculation in node js. I have followed by the answer in link .It worked as expected and had started to do calculation. Here how can I get the details from the mongodb in child file.I am using mongoose for mongodb. My sample code is below main.js var childprocess = require('child_process'); var child = childprocess .fork(__dirname + '/childpage'); child.on('message', function(m) { // Receive results from child process console.log('received: ' + m); }); childpage var User = require('../models/User'); //mongoose schema var users= {}; User.find({}, function

Sending JSON from Python to Node via child_process gets truncated if too long, how to fix?

孤人 提交于 2019-11-29 17:21:20
My Node & Python backend is running just fine, but I now encountered an issue where if a JSON I'm sending from Python back no Node is too long, it gets split into two and my JSON.parse at the Node side fails. How should I fix this? For example, the first batch clips at ... [1137.6962355826706, -100.78015825640887], [773.3834338399517, -198 and the second one has the remaining few entries .201506231888], [-87276.575065248, -60597.8827676457], [793.1850250453127, -192.1674702207991], [1139.4465453979683, -100.56741252031816], [780.498416769341, -196.04064849430705]]} Do I have to create some

Nodejs - process hangs on exit (Ctrl+C)

青春壹個敷衍的年華 提交于 2019-11-29 16:42:53
问题 I have a node.js project which does many things, it spawns child processes, it opens an http and socket.io server, etc.. When I run it from the console, closing it with Ctrl+C , it just hangs. From webstorm, stopping the process is a two-step process, first I hit stop, then I need to hit the button again, only the second time the button is a skull icon. Now, I understand it leaves something open or hanging, but I just can't figure out what, I tried to track all the places where I start a

How to transfer/stream big data from/to child processes in node.js without using the blocking stdio?

不羁岁月 提交于 2019-11-29 03:07:51
问题 I have a bunch of (child)processes in node.js that need to transfer large amounts of data. When I read the manual it says the the stdio and ipc inferface between them are blocking, so that won't do. I'm looking into using file descriptors but I cannot find a way to stream from them (see my other more specific question How to stream to/from a file descriptor in node?) I think I might use a net socket, but I fear that has unwanted overhead. I also see this but it not the same (and has no

Write to spawned process stdin nodejs?

我是研究僧i 提交于 2019-11-29 02:35:10
问题 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) { console.log(data.toString().trim()); // tells me to input my data child.stdin.write('my data\n'); }); After I input my data the child script should continue but instead it hang in there. Solution Actually the above code work for me. I'm using commander

Nodejs Child Process: write to stdin from an already initialised process

こ雲淡風輕ζ 提交于 2019-11-28 17:46:07
I am trying to spawn an external process phantomjs using node's child_process and then send information to that process after it was initialized, is that possible? I have the following code: var spawn = require('child_process').spawn, child = spawn('phantomjs'); child.stdin.setEncoding = 'utf-8'; child.stdout.pipe(process.stdout); child.stdin.write("console.log('Hello from PhantomJS')"); But the only thing I got on the stdout is the initial prompt for phantomjs console. phantomjs> So it seems the child.stdin.write is not making any effect. I am not sure I can send additional information to

Sending JSON from Python to Node via child_process gets truncated if too long, how to fix?

[亡魂溺海] 提交于 2019-11-28 10:56:32
问题 My Node & Python backend is running just fine, but I now encountered an issue where if a JSON I'm sending from Python back no Node is too long, it gets split into two and my JSON.parse at the Node side fails. How should I fix this? For example, the first batch clips at ... [1137.6962355826706, -100.78015825640887], [773.3834338399517, -198 and the second one has the remaining few entries .201506231888], [-87276.575065248, -60597.8827676457], [793.1850250453127, -192.1674702207991], [1139

Start another node application using node.js?

六月ゝ 毕业季﹏ 提交于 2019-11-28 04:40:28
I have two separate node applications. I'd like one of them to be able to start the other one at some point in the code. How would I go about doing this? Use child_process.fork() . It is similar to spawn() , but is used to create entire new instances of V8. Therefore it is specially used for running new instances of Node. If you are just executing a command, then use spawn() or exec() . var fork = require('child_process').fork; var child = fork('./script'); Note that when using fork() , by default, the stdio streams are associated with the parent. This means all output and errors will be shown

How to get return value from child process to parent?

流过昼夜 提交于 2019-11-28 04:37:45
问题 I'm supposed to return the sum of first 12 terms of Fibonacci series from child process to parent one but instead having 377 , parent gets 30976 . #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> int main(int argc, char *argv[]) { pid_t childpid; int i, fib_sum=0, fib1=1, fib2=1, temp, status; childpid=fork(); if(childpid!=0) { wait(&status); fprintf(stderr, "%d\n", status); } else { for(i=1; i<=12; i++) { temp=fib1; fib_sum=fib1+fib2;