Skip to content

NodeJS child_process spawning experiments (blocking/streaming/signals)

Notifications You must be signed in to change notification settings

craigtaub/child_process_experiments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodeJS child process experiments

  • spawning child (and sub) processes
  • blocking processes (stream + timers)
  • sending signals

Keeping process open:

  • pipes for stdin/stdout+stderr are established between the parent Node.js process and the spawned child
  • holding process/shell open:
    • timers + stream (of data, via TCP sockets) hold it
    • spawn(process.execPath, args) -> holds (stream)
    • process.stdout.on('data') -> holds (stream)
      • same applies to parent or child process
    • setTimeout(() => { /* code */ }, 1000) - holds (timer)
    • process.on('SIGINT') -> doesnt hold (not a stream, an event)
  • WHY:
    • child process waits to read all of its input
    • the child will not continue until the stream has been closed via end() or kill().
    • process.stdin.end() OR process.kill('SIGINT')
    • can pass kill event down stack i.e. parent -> child -> baby
  • 'EXIT' event - emitted after the child process ends
    • IF nothing holding process will always run at end of script
    • ELSE signal could manually have exited it, will have signal.

About

NodeJS child_process spawning experiments (blocking/streaming/signals)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published