Fork

This lesson discusses the caveats to remember when forking processes.

We'll cover the following...

Fork

Fork is the default method Python uses to create processes on Unix based systems.

Fork is one of the options a developer can choose to create processes. We'll need to examine the underlying operating system's fork system call in order to understand how the fork option works in Python.

Fork system call

There are two families of system calls, fork and exec that can be invoked by a process to create subprocesses on Unix based systems. A process can invoke this system call and get an almost clone of itself. We qualify the statement with almost because not everything is copied when a fork happens. The exact list of what isn't copied can be found by checking out the manpage of fork on your platform (type "man fork" in terminal). The child process gets an identical memory image so any open file descriptors are copied. However, multiple threads of a process don't get copied. Any threads running in the parent process do not exist in the child ...