Creating a Process: Windows vs. Linux

Pavel Yosifovich

Author

Pavel Yosifovich has 25+ years as Software developer, trainer, consultant, author, and speaker. Co-author of “Windows Internals”. Author of “Windows Kernel Programming”, “Windows 10 System Programming, as well as System and kernel programming courses and “Windows Internals” series.

In Windows, creating a process is a single step. You call CreateProcess, the kernel creates a new process with its own address space and handle table, and it starts the executable you pointed it at. The call returns immediately, so the caller can keep working while the new process runs.

On Linux, the same idea is split into two steps. First you call fork, which duplicates the current process. The child gets a copy of the parent’s memory and continues executing from the same point. Then, in the child, you call one of the exec family of functions, which replaces the child’s program with a different executable. The parent keeps running throughout.

Neither approach is strictly better. The two-step model gives the child a chance to adjust its state between fork and exec (for example, redirecting file descriptors) before it becomes a different program. The one-step model is simpler to call, but it asks the caller to describe everything about the new process up front.

A simple Windows example

The Windows version is short. You fill in the command line, call CreateProcessW, and check the return value. The API is documented here: CreateProcessW. Once the call succeeds, the new process has its own process ID, which you can read with GetProcessId if you hold a handle to it.

The same thing on Linux

On Linux, the example is a small C++ program built with GCC and run under WSL:

1. Call fork. It returns a value greater than zero in the parent (the child’s process ID), zero in the child, and a negative value on error. 2. In the child, call execv with the path of the program to run and an argument array. The argument array starts with the program name by convention, followed by its arguments, and ends with a null pointer. 3. Check the return value of execv. If it fails, it returns a negative value and sets errno, which perror can print.

Two things tripped up the compiler along the way. execv expects a non-const array of non-const char* pointers, so a string literal does not match its signature without a cast. The second is that execv does not search PATH. Running ps through execv fails with “No such file or directory” unless you pass the full path, /usr/bin/ps. The shell does the PATH lookup for you, and the exec functions do not. The execvp variant does search PATH, if you would rather not hard-code the location.

When the child runs, it stops being a copy of the parent and becomes ps. The process ID printed by the child matches the one shown in the ps aux output, which is a good way to confirm that the process was replaced in place rather than started fresh.

What to take from this

Windows gives you one call that creates a process from scratch. Linux gives you a copy of the current process, which you then reshape. Both create a new address space and a new process, and both let the parent continue. The difference is where the work happens: on Windows, the description of the new process goes into one call; on Linux, it happens in the child between two calls.

For a deeper look at how processes, address spaces, and the Linux kernel’s process model work, see the Linux Internals for Windows Professionals course.


$1,500 or $157 X 10 payments

Learn Linux internals from the source. Pavel Yosifovich takes the Windows internals you know and shows how Linux handles the same ideas. Live course: 8 sessions of 4 hours, starting December 14, 2026.

blue depth
Pavel Yosifovich

About the author

Pavel Yosifovich has 25+ years as Software developer, trainer, consultant, author, and speaker. Co-author of “Windows Internals”. Author of “Windows Kernel Programming”, “Windows 10 System Programming, as well as System and kernel programming courses and “Windows Internals” series.