Q58: How do you gracefully disconnect a child process spawned via fork()?

When spawning child processes using child_process.fork(), an IPC channel is established. To cleanly disconnect without abruptly killing ongoing tasks, call child.disconnect(). This closes the IPC channel, allows pending events to drain, and permits the child process to exit naturally once its event loop completes.

Key Takeaways
  • child.disconnect() closes the Inter-Process Communication (IPC) channel cleanly.
  • Allows child processes to complete pending tasks and terminate without sending SIGKILL signals.
Knowledge Check

What happens when child.disconnect() is called on a IPC-connected child process?