Problem Statement
What is the difference between fork() and spawn() in Node.js?
Explanation
Both create new processes. `spawn()` launches a new process with a given command. `fork()` is a special case of `spawn()` that creates a new Node.js instance for parallel execution, ideal for running multiple workers.
Code Solution
SolutionRead Only
const { fork, spawn } = require('child_process');
const child = fork('worker.js'); // new Node process
const run = spawn('ls', ['-lh']); // system command