SlideShare a Scribd company logo
Node - Child Process
Jason
Child Process
● The child_process module provides the ability to spawn child processes in a
manner that is similar.
var child_process = require (‘child_process’);
Child Process
● exec
● spawn
● execFile
● fork
exec
spawns a shell and runs a command within that shell, passing the stdout and
stderr to a callback function when complete.
exec(command[, options][, callback])
var cp = require('child_process');
cp.exec('node -v', (err, stdout, stderr) => {
if(err){ return; }
console.log(stdout);
});
execFile
similar to child_process.exec() except that it spawns the command directly without
first spawning a shell.
execFile(file[, args][, options][, callback])
var cp = require('child_process');
cp.execFile('/bin/ls', ['-v'], (error, stdout, stderr) => {
if (error) { throw error; }
console.log(stdout);
});
exec VS execFile
var path = ";pwd";
child_process.exec('ls ' + path, (err, stdout, stderr)=> {
console.log(stdout);
});
var path = ".;pwd";
child_process.execFile('ls', ['-l', path], (err, stdout, stderr) => {
console.log(stdout)
});
spawn
spawn(command[, args][, options])
var cp = require('child_process');
var path = '.';
var ls = cp.spawn('ls', ['-l', path]);
ls.stdout.on('data', (data) => { ….. });
ls.stderr.on('data', (data) => { …. });
ls.on('close', (code) => { ….. });
exec VS spawn
exec :default options
{
encoding: 'utf8',
timeout: 0,
maxBuffer: 200*1024,
killSignal: 'SIGTERM',
cwd: null,
env: null
}
spawn:default options
{
cwd: undefined,
env: process.env
}
fork
fork(modulePath[, args][, options])
● spawns a new Node.js process and invokes a specified module
● The returned ChildProcess will have an additional communication channel built-in that allows messages
to be passed back and forth between the parent and child.
fork('./child.js')
∣∣
spawn('node', ['./child.js'])
fork
fork(modulePath[, args][, options]) child.js
parent.js
var cp = require('child_process');
var n = cp.fork('./child.js');
n.on('message', (m) => {
console.log('parent got message:', m);
});
n.send({ hello: 'world' });
process.on('message', (m) => {
console.log('child got message:', m);
});
process.send({ foo: 'bar' });
Reference
Node child_process
https://nodejs.org/api/child_process.html

More Related Content

What's hot

Functional php
Functional phpFunctional php
Functional php
Jean Carlo Machado
 
Git avançado
Git avançadoGit avançado
Git avançado
Jean Carlo Machado
 
Ansible Callback Plugins
Ansible Callback PluginsAnsible Callback Plugins
Ansible Callback Plugins
jtyr
 
Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHPThomas Weinert
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門lestrrat
 
Alex Troush - IEx Cheat Sheet. Guide to Win with IEx on your Day to Day Job
Alex Troush - IEx Cheat Sheet. Guide to Win with IEx on your Day to Day JobAlex Troush - IEx Cheat Sheet. Guide to Win with IEx on your Day to Day Job
Alex Troush - IEx Cheat Sheet. Guide to Win with IEx on your Day to Day Job
Elixir Club
 
第1回PHP拡張勉強会
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会
Ippei Ogiwara
 
Linux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptLinux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell script
Kenny (netman)
 
Sample file processing
Sample file processingSample file processing
Sample file processingIssay Meii
 
Cooking pies with Celery
Cooking pies with CeleryCooking pies with Celery
Cooking pies with Celery
Aleksandr Mokrov
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
xSawyer
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
Ramesh Nair
 
Shell Script Tutorial
Shell Script TutorialShell Script Tutorial
Shell Script Tutorial
Quang Minh Đoàn
 
Debugging JavaScript with Chrome
Debugging JavaScript with ChromeDebugging JavaScript with Chrome
Debugging JavaScript with Chrome
Igor Zalutsky
 
objection - runtime mobile exploration
objection - runtime mobile explorationobjection - runtime mobile exploration
objection - runtime mobile exploration
SensePost
 
Spock framework
Spock frameworkSpock framework
Spock framework
Djair Carvalho
 
Large scale machine learning projects with r suite
Large scale machine learning projects with r suiteLarge scale machine learning projects with r suite
Large scale machine learning projects with r suite
Wit Jakuczun
 

What's hot (20)

Functional php
Functional phpFunctional php
Functional php
 
Git avançado
Git avançadoGit avançado
Git avançado
 
Ansible Callback Plugins
Ansible Callback PluginsAnsible Callback Plugins
Ansible Callback Plugins
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
 
Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHP
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
 
Alex Troush - IEx Cheat Sheet. Guide to Win with IEx on your Day to Day Job
Alex Troush - IEx Cheat Sheet. Guide to Win with IEx on your Day to Day JobAlex Troush - IEx Cheat Sheet. Guide to Win with IEx on your Day to Day Job
Alex Troush - IEx Cheat Sheet. Guide to Win with IEx on your Day to Day Job
 
第1回PHP拡張勉強会
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会
 
Linux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell scriptLinux fundamental - Chap 14 shell script
Linux fundamental - Chap 14 shell script
 
Fork handout
Fork handoutFork handout
Fork handout
 
Sample file processing
Sample file processingSample file processing
Sample file processing
 
Cooking pies with Celery
Cooking pies with CeleryCooking pies with Celery
Cooking pies with Celery
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
 
Shell Script Tutorial
Shell Script TutorialShell Script Tutorial
Shell Script Tutorial
 
Debugging JavaScript with Chrome
Debugging JavaScript with ChromeDebugging JavaScript with Chrome
Debugging JavaScript with Chrome
 
objection - runtime mobile exploration
objection - runtime mobile explorationobjection - runtime mobile exploration
objection - runtime mobile exploration
 
Spock framework
Spock frameworkSpock framework
Spock framework
 
Large scale machine learning projects with r suite
Large scale machine learning projects with r suiteLarge scale machine learning projects with r suite
Large scale machine learning projects with r suite
 
nginx mod PSGI
nginx mod PSGInginx mod PSGI
nginx mod PSGI
 

Viewers also liked

Presentacion rosa
Presentacion rosaPresentacion rosa
Presentacion rosa
rosa tenorio
 
Manual de redes
Manual de redesManual de redes
Manual de redes
Less Perez
 
Parenting stress conceptual figure
Parenting stress conceptual figureParenting stress conceptual figure
Parenting stress conceptual figure
Kirby Deater-Deckard
 
Listex general presentation (Feb 2017)
Listex general presentation (Feb 2017)Listex general presentation (Feb 2017)
Listex general presentation (Feb 2017)
Zakhar Dikhtyar
 
BP#62_p40-43 fine art nudes
BP#62_p40-43 fine art nudesBP#62_p40-43 fine art nudes
BP#62_p40-43 fine art nudesLynn Gail
 
MANUAL DE REDES
MANUAL DE REDESMANUAL DE REDES
MANUAL DE REDES
Leslye Avelar
 
Love
LoveLove
Guía de Estudio - Modulo IV: Análisis Financiero
Guía de Estudio - Modulo IV: Análisis FinancieroGuía de Estudio - Modulo IV: Análisis Financiero
Guía de Estudio - Modulo IV: Análisis Financiero
ORASMA
 
Estatística e Probabilidade - 6 Medidas de Posição
Estatística e Probabilidade - 6 Medidas de PosiçãoEstatística e Probabilidade - 6 Medidas de Posição
Estatística e Probabilidade - 6 Medidas de Posição
Ranilson Paiva
 
Fidaxomicin in cdiff
Fidaxomicin in cdiffFidaxomicin in cdiff
Fidaxomicin in cdiff
Isabella Nga Lai
 
Hacia donde van las universidades peruanas
Hacia donde van las universidades peruanasHacia donde van las universidades peruanas
Hacia donde van las universidades peruanas
nguillermo
 
Growth Opportunities in Medical Nutrition 2017 sample proposal
Growth Opportunities in Medical Nutrition 2017 sample proposalGrowth Opportunities in Medical Nutrition 2017 sample proposal
Growth Opportunities in Medical Nutrition 2017 sample proposal
Brand Acumen
 
Radio y television
Radio y televisionRadio y television
Radio y television
UPTC LIMITED
 
Examen de nombramiento docente agosto 2015 tecnico productivo
Examen de nombramiento docente agosto 2015 tecnico productivoExamen de nombramiento docente agosto 2015 tecnico productivo
Examen de nombramiento docente agosto 2015 tecnico productivo
Colegio
 
Demostraciones clase
Demostraciones claseDemostraciones clase
Demostraciones clase
Marco Coloma Yunganina
 
Dayclic 09 mars 2017 HumaNum Loire nantes
Dayclic 09 mars 2017 HumaNum Loire nantesDayclic 09 mars 2017 HumaNum Loire nantes
Dayclic 09 mars 2017 HumaNum Loire nantes
Bourrion Daniel
 
Biz-Tech Quiz Set 2017
Biz-Tech Quiz Set 2017Biz-Tech Quiz Set 2017
Biz-Tech Quiz Set 2017
Suvam Palo
 

Viewers also liked (17)

Presentacion rosa
Presentacion rosaPresentacion rosa
Presentacion rosa
 
Manual de redes
Manual de redesManual de redes
Manual de redes
 
Parenting stress conceptual figure
Parenting stress conceptual figureParenting stress conceptual figure
Parenting stress conceptual figure
 
Listex general presentation (Feb 2017)
Listex general presentation (Feb 2017)Listex general presentation (Feb 2017)
Listex general presentation (Feb 2017)
 
BP#62_p40-43 fine art nudes
BP#62_p40-43 fine art nudesBP#62_p40-43 fine art nudes
BP#62_p40-43 fine art nudes
 
MANUAL DE REDES
MANUAL DE REDESMANUAL DE REDES
MANUAL DE REDES
 
Love
LoveLove
Love
 
Guía de Estudio - Modulo IV: Análisis Financiero
Guía de Estudio - Modulo IV: Análisis FinancieroGuía de Estudio - Modulo IV: Análisis Financiero
Guía de Estudio - Modulo IV: Análisis Financiero
 
Estatística e Probabilidade - 6 Medidas de Posição
Estatística e Probabilidade - 6 Medidas de PosiçãoEstatística e Probabilidade - 6 Medidas de Posição
Estatística e Probabilidade - 6 Medidas de Posição
 
Fidaxomicin in cdiff
Fidaxomicin in cdiffFidaxomicin in cdiff
Fidaxomicin in cdiff
 
Hacia donde van las universidades peruanas
Hacia donde van las universidades peruanasHacia donde van las universidades peruanas
Hacia donde van las universidades peruanas
 
Growth Opportunities in Medical Nutrition 2017 sample proposal
Growth Opportunities in Medical Nutrition 2017 sample proposalGrowth Opportunities in Medical Nutrition 2017 sample proposal
Growth Opportunities in Medical Nutrition 2017 sample proposal
 
Radio y television
Radio y televisionRadio y television
Radio y television
 
Examen de nombramiento docente agosto 2015 tecnico productivo
Examen de nombramiento docente agosto 2015 tecnico productivoExamen de nombramiento docente agosto 2015 tecnico productivo
Examen de nombramiento docente agosto 2015 tecnico productivo
 
Demostraciones clase
Demostraciones claseDemostraciones clase
Demostraciones clase
 
Dayclic 09 mars 2017 HumaNum Loire nantes
Dayclic 09 mars 2017 HumaNum Loire nantesDayclic 09 mars 2017 HumaNum Loire nantes
Dayclic 09 mars 2017 HumaNum Loire nantes
 
Biz-Tech Quiz Set 2017
Biz-Tech Quiz Set 2017Biz-Tech Quiz Set 2017
Biz-Tech Quiz Set 2017
 

Similar to Node child process

Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
Piotr Pelczar
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
Johannes Hoppe
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
Johannes Hoppe
 
Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modules
jerryorr
 
Ember testing internals with ember cli
Ember testing internals with ember cliEmber testing internals with ember cli
Ember testing internals with ember cli
Cory Forsyth
 
Containers: What are they, Really?
Containers: What are they, Really?Containers: What are they, Really?
Containers: What are they, Really?
Sneha Inguva
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bitsChris Saylor
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockRobot Media
 
Pocket Talk; Spock framework
Pocket Talk; Spock frameworkPocket Talk; Spock framework
Pocket Talk; Spock framework
Infoway
 
OS presentation (1).pptx
OS presentation (1).pptxOS presentation (1).pptx
OS presentation (1).pptx
Jenish62
 
System call (Fork +Exec)
System call (Fork +Exec)System call (Fork +Exec)
System call (Fork +Exec)
Amit Ghosh
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}.toster
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
TrevorBurnham
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
Bruno Scopelliti
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
Giovanni Scerra ☃
 
Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy Cresine
Movel
 
Program Assignment Process ManagementObjective This program a.docx
Program Assignment  Process ManagementObjective This program a.docxProgram Assignment  Process ManagementObjective This program a.docx
Program Assignment Process ManagementObjective This program a.docx
wkyra78
 
C++11 Multithreading - Futures
C++11 Multithreading - FuturesC++11 Multithreading - Futures
C++11 Multithreading - Futures
GlobalLogic Ukraine
 

Similar to Node child process (20)

Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
 
Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modules
 
Ember testing internals with ember cli
Ember testing internals with ember cliEmber testing internals with ember cli
Ember testing internals with ember cli
 
Containers: What are they, Really?
Containers: What are they, Really?Containers: What are they, Really?
Containers: What are they, Really?
 
Node intro
Node introNode intro
Node intro
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
 
Pocket Talk; Spock framework
Pocket Talk; Spock frameworkPocket Talk; Spock framework
Pocket Talk; Spock framework
 
OS presentation (1).pptx
OS presentation (1).pptxOS presentation (1).pptx
OS presentation (1).pptx
 
System call (Fork +Exec)
System call (Fork +Exec)System call (Fork +Exec)
System call (Fork +Exec)
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
Introduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy CresineIntroduction to ES6 with Tommy Cresine
Introduction to ES6 with Tommy Cresine
 
Program Assignment Process ManagementObjective This program a.docx
Program Assignment  Process ManagementObjective This program a.docxProgram Assignment  Process ManagementObjective This program a.docx
Program Assignment Process ManagementObjective This program a.docx
 
C++11 Multithreading - Futures
C++11 Multithreading - FuturesC++11 Multithreading - Futures
C++11 Multithreading - Futures
 

More from LearningTech

vim
vimvim
PostCss
PostCssPostCss
PostCss
LearningTech
 
ReactJs
ReactJsReactJs
ReactJs
LearningTech
 
Docker
DockerDocker
Docker
LearningTech
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
LearningTech
 
node.js errors
node.js errorsnode.js errors
node.js errors
LearningTech
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
LearningTech
 
Expression tree
Expression treeExpression tree
Expression tree
LearningTech
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
LearningTech
 
flexbox report
flexbox reportflexbox report
flexbox report
LearningTech
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
LearningTech
 
Reflection & activator
Reflection & activatorReflection & activator
Reflection & activator
LearningTech
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
LearningTech
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
LearningTech
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
LearningTech
 
Expression tree
Expression treeExpression tree
Expression tree
LearningTech
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
LearningTech
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
LearningTech
 
git command
git commandgit command
git command
LearningTech
 
Asp.net MVC DI
Asp.net MVC DIAsp.net MVC DI
Asp.net MVC DI
LearningTech
 

More from LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection & activator
Reflection & activatorReflection & activator
Reflection & activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 
Asp.net MVC DI
Asp.net MVC DIAsp.net MVC DI
Asp.net MVC DI
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

Node child process

  • 1. Node - Child Process Jason
  • 2. Child Process ● The child_process module provides the ability to spawn child processes in a manner that is similar. var child_process = require (‘child_process’);
  • 3. Child Process ● exec ● spawn ● execFile ● fork
  • 4. exec spawns a shell and runs a command within that shell, passing the stdout and stderr to a callback function when complete. exec(command[, options][, callback]) var cp = require('child_process'); cp.exec('node -v', (err, stdout, stderr) => { if(err){ return; } console.log(stdout); });
  • 5. execFile similar to child_process.exec() except that it spawns the command directly without first spawning a shell. execFile(file[, args][, options][, callback]) var cp = require('child_process'); cp.execFile('/bin/ls', ['-v'], (error, stdout, stderr) => { if (error) { throw error; } console.log(stdout); });
  • 6. exec VS execFile var path = ";pwd"; child_process.exec('ls ' + path, (err, stdout, stderr)=> { console.log(stdout); }); var path = ".;pwd"; child_process.execFile('ls', ['-l', path], (err, stdout, stderr) => { console.log(stdout) });
  • 7. spawn spawn(command[, args][, options]) var cp = require('child_process'); var path = '.'; var ls = cp.spawn('ls', ['-l', path]); ls.stdout.on('data', (data) => { ….. }); ls.stderr.on('data', (data) => { …. }); ls.on('close', (code) => { ….. });
  • 8. exec VS spawn exec :default options { encoding: 'utf8', timeout: 0, maxBuffer: 200*1024, killSignal: 'SIGTERM', cwd: null, env: null } spawn:default options { cwd: undefined, env: process.env }
  • 9. fork fork(modulePath[, args][, options]) ● spawns a new Node.js process and invokes a specified module ● The returned ChildProcess will have an additional communication channel built-in that allows messages to be passed back and forth between the parent and child. fork('./child.js') ∣∣ spawn('node', ['./child.js'])
  • 10. fork fork(modulePath[, args][, options]) child.js parent.js var cp = require('child_process'); var n = cp.fork('./child.js'); n.on('message', (m) => { console.log('parent got message:', m); }); n.send({ hello: 'world' }); process.on('message', (m) => { console.log('child got message:', m); }); process.send({ foo: 'bar' });

Editor's Notes

  1. http://javascript.ruanyifeng.com/nodejs/child-process.html#toc2 https://nodejs.org/api/child_process.html#child_process_child_process
  2. http://blog.fens.me/nodejs-child-process/
  3. fork('./child.js') spawn('node', ['./child.js'])
  4. fork('./child.js') spawn('node', ['./child.js'])