IT lexicon › Programming › exec

exec

Programming På svenska → Updated: 2026-07-31

The system call that swaps a process's contents for another program — same process, new code.

Where fork() creates a new process, exec() keeps the process but discards its memory, loads a new executable and starts at its entry point. The PID, open file descriptors and working directory carry over. On success the call never returns — there is no code left to return to.

The fork-then-exec combination is Unix's way of launching programs, and the split is deliberate: between the two calls the child can change things that should apply to the new program — redirect standard output, set environment variables, drop privileges. That is exactly what a shell does when you type a command containing >.

← Back to the lexicon