child process
A process started by another process, its parent, from which it inherits a copy of the environment and current directory.
In more detail
Because the child gets copies, nothing it changes, such as variables or the current directory, flows back to the parent. The child has its own memory and process ID, so a crash there does not bring the parent down. The parent can talk to it through pipes and wait for its exit code to learn whether it succeeded.
Examples
On Linux a process usually creates a child by copying itself with fork and then loading a new program with exec. Your shell starts each command you type as a child and waits for it unless you put it in the background. The child inherits the parent's environment, open file descriptors and identity.Node.js starts them with spawn(), execFile(), exec() and fork() from node:child_process.subprocess.run([sys.executable, "-c", PROBE], env={"PATH": os.environ["PATH"], "LANG": "C"})The course passes an explicit, minimal env to subprocess.run instead of handing over everything the parent holds.Related terms
- process — A program that is currently running, with its own memory and a numeric identifier.
- subshell — A child copy of the current shell, created by ( ), by command substitution and by each stage of a pipe.
- export builtin — The builtin that marks a shell variable so child processes receive a copy of it in their environment.
- source builtin — The builtin that runs a file's commands in the current shell instead of in a new one; the POSIX spelling is a single dot.
- parent process — The process that started another process; every process except the first records its parent's PID.
- shell — The program that reads the commands you type, runs them and shows the results; sh and bash are common ones.
- background job — A command started with & at the end of the line, which runs while the shell immediately gives you the prompt back.
- spawn() — The node:child_process function that starts a program with a list of arguments and gives you its standard input, output and error as streams.
- execFile() — The node:child_process function that runs a program directly, without a shell, and buffers its output.
- child_process.fork() — The node:child_process function that starts another Node.js process running a given script, with a built-in message channel to it.
- environment variable — A named setting such as PORT=8000 that a program reads from its surroundings when it starts.
- least privilege — Giving every program and person only the access they need, and nothing more.
Taught in
- Shell Variables, The Environment And export — Bash Scripting & Command Line Automation
- Command Substitution And Subshells — Bash Scripting & Command Line Automation
- Shebangs, Permissions And Three Ways To Run — Bash Scripting & Command Line Automation
- What A Kernel Does, And What It Refuses To Do — Linux Fundamentals & Systems Administration
- What A Process Is — Linux Fundamentals & Systems Administration
- Child Processes: spawn, execFile, fork & IPC — Node.js Internals & Backend Services
- Global Error Trapping: uncaughtException & Exits — Node.js Internals & Backend Services
- The Environment Variable Trap — Application Security & Threat Modeling for Engineers
- Injection In All Its Forms — Application Security & Threat Modeling for Engineers