Node.JS child processes being killed when parent dies
you need to set the detached option
If the detached option is set, the child process will be made the
leader of a new process group. This makes it possible for the child to
continue running after the parent exits.
var child = spawn('prg', [], {
detached: true,
stdio: [ 'ignore', out, err ]
});
parent process kills child process, even though detached is set to true
Aha! Of course. Those stupid Node docs!
This works.
const n = cp.spawn('node', ['lib/transpile/watch-transpile.js'], {
detached: true,
stdio: ['ignore', 'ignore', 'ignore']
});
You explicitly ignore each stdio stream, not just using 'ignore' once; the docs don't mention this directly, but it makes sense given that the stdio property is an array.
See this issue on Github: https://github.com/nodejs/node/issues/7269#issuecomment-225698625
kill all child_process when node process is killed
You need to listen for the process exit event and kill the child processes then. This should work for you:
var args = "ffmpeg -i in.avi out.avi"
var a = child_process.exec(args , function(err, stdout,stderr){});
var b = child_process.exec(args , function(err, stdout,stderr){});
process.on('exit', function () {
a.kill();
b.kill();
});
Node: child_process.exec() process continuing after parent process dies
Different operating systems handle child processes differently. I usually add in handler like this:
['SIGINT', 'SIGHUP', 'SIGTERM'].forEach(function(signal) {
process.addListener(signal, gracefulShutdown);
});
gracefulShutdown
should do things like close sockets and quit processes (process.stop()
)
OH... And I just reread your question. ctrl-z pauses a process, it doesn't kill it. If you use fg
or bg
, it will bring the process back into the foreground/background. To quick the REPL, use ctrl-c twice.
Related Topics
Get Time in Milliseconds Without an Installing an Extra Package
Multiple Option Arguments Using Getopts (Bash)
Does Madvise(_, _, Madv_Dontneed) Instruct the Os to Lazily Write to Disk
Fork() Failing with Out of Memory Error
Nasm - Symbol 'Printf' Causes Overflow in R_X86_64_Pc32 Relocation
Release of Flock in Case of Errors
How to Use the Linux Flock Command to Prevent Another Root Process from Deleting a File
Change .Eclipse Folder in Linux
PDF Lib Install Fail on Linux Server. Using Pecl Install PDFlib
Sharing Devices (Webcam, Usb Drives, etc) with Docker
How to Export Symbols from a Shared Library
What Is the Windows Equivalent of Linux Command Wc -L
Find and Replace Text in a File Between Range of Lines Using Sed
Curl Simple File Upload - 417 Expectation Failed
Why Do I Get "Suspended (Tty Output)" in One Terminal But Not in Others
Creating Permanent Executable Aliases
How Is Stack Size of Linux Process Related to Pthread, Fork and Exec