child-process

How to control execution of parent process after execl() call in C program?

别等时光非礼了梦想. 提交于 2019-12-13 18:27:58
问题 I have simple C program which executes an application using fork() and execl(). If execl() fails to run the application, then I have to call a function in the parent process and exit from the child process. If execl() successfully runs the application, then I have show a success log from the parent process. So, parent process should wait for the child's execl() call (just the call, not till the end of execution of the application), get some information about it status, and then make decisions

In node.js, how to use child_process.exec so all can happen asynchronously?

核能气质少年 提交于 2019-12-13 16:57:25
问题 I have a server built on node.js. Below is one of the request handler functions: var exec = require("child_process").exec function doIt(response) { //some trivial and fast code - can be ignored exec( "sleep 10", //run OS' sleep command, sleep for 10 seconds //sleeping(10), //commented out. run a local function, defined below. function(error, stdout, stderr) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write(stdout); response.end(); }); //some trivial and fast code - can

Node.js - Sending a big object to child_process is slow

我与影子孤独终老i 提交于 2019-12-13 12:24:53
问题 My Use-case is as follows: I make plenty of rest API calls from my node server to public APIs. Sometime the response is big and sometimes its small. My use-case demands me to stringify the response JSON. I know a big JSON as response is going to block my event loop. After some research i decided to use child_process.fork for parsing these responses, so that the other API calls need not wait. I tried sending a big 30 MB JSON file from my main process to the forked child_process. It takes so

Explain this code's working; how the child process returns values and where?

烂漫一生 提交于 2019-12-13 12:12:33
问题 I don't get how the value is returned by a child process and to whom? Output is 6, 7 ; question source: http://www.cs.utexas.edu/~mwalfish/classes/s11-cs372h/hw/sol1.html Program 1: main() { val = 5; if(fork()) wait(&val); val++; printf("%d\n", val); return val; } 回答1: Main process: val = 5; wait(&val); // wait until child finishes Child process: val++; // val becomes 6 printf("%d\n", val); // prints 6 return val; // return val back to main process Main process: wait(&val); // val becomes 6

How to spawn a grandchild process for a child process?

和自甴很熟 提交于 2019-12-13 07:37:23
问题 I have spawned a child process, below is the code: const spawn = require('child_process').spawn; const ls = spawn('ls', ['-lh', '/usr'], { detached: true }); ls.stdout.on('data', (data) => { console.log(`stdout: ${data}`); fs.writeFileSync('path-to-test.txt', 'stdout'); }); ls.stderr.on('data', (data) => { console.log(`stderr: ${data}`); fs.writeFileSync('path-to-test.txt', 'stderr'); }); ls.on('close', (code) => { console.log(`child process exited with code ${code}`); }); With option

Child_process throw an Error: write EPIPE

霸气de小男生 提交于 2019-12-13 02:18:58
问题 I just practise some node js code about child_process @the link My node version is V5.2.0 on windows 7. // master.js var cp=require("child_process"); var np=cp.fork("./console.js"); // line B // block C np.stdout.on("data",function(data){ console.log("child process output:"+data); }); np.stderr.on("data", function(err){ console.log("child process output error:"+err); }); np.on("close", function () { console.log("child process exit"); }); // end of block C np.send({Hello:"world"}); np.on(

Advantages of node.js addon vs child_process

不打扰是莪最后的温柔 提交于 2019-12-12 15:13:34
问题 What would be the advantages, if any, of using a node.js addon written in C/C++ compared to calling a binary with arguments through child_process? More specifically, I have a small program, which accepts possibly up to a few hundred arguments and returns a boolean. 回答1: There is a huge difference. C++ Addon is native code which is running as part of main application (on the same level as JS does). But if you use child_process , node will start new process and there is a huge overhead

Result of ps au | grep ssh different in Node.js (using spawn/pipe) vs shell

筅森魡賤 提交于 2019-12-12 12:13:54
问题 I'm playing around with node streams and child processes. So I want to emulate next shell command with pipes: ps au | grep ssh So I wrote next code: var spawn = require('child_process').spawn; var ps = spawn('ps', ['au']); var grep = spawn('grep', ['ssh']); ps.stdout.pipe(grep.stdin); grep.stdout.on('data', function(data) { console.log(data) }); Then I run it, but nothing happens. What did I do wrong? P.S. - I know about: require('child_process') .exec('ps au | grep ssh', function(err, stdout

Creating Callbacks for required modules in node.js

只愿长相守 提交于 2019-12-12 07:24:16
问题 Is there any possibilitie for creating some kind of a callback within a module created by my own? My problem is that I have written a module for my application. Within this module is done some task and now my main-app should get a feedback that the module finished his task. The following describes what i want but wont work ofcourse... //module mymod.js function start() { var done = false; //do some tasks done = true; } exports.done = done; Main App var mymod = require("./mymod.js"); while(

How Secure is using execFile for Bash Scripts?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 03:35:20
问题 I have a node.js app which is using the child_process.execFile command to run a command-line utility. I'm worried that it would be possible for a user to run commands locally (a rm / -rf horror scenario comes to mind). How secure is using execFile for Bash scripts? Any tips to ensure that flags I pass to execFile are escaped by the unix box hosting the server? Edit To be more precise, I'm more wondering if the arguments being sent to the file could be interpreted as a command and executed.