Fork-Join Concept

Table of Contents

The fork-join is a basic method of expressing concurrency within a computation. This is implemented in the UNIX operating system as system calls.



The fork() call creates a new child process which runs concurrently with the parent. The child process is an exact copy of the parent except that it has a new process id. The fork() creates concurrency.


The join() is called by both the parent and the child. The child process calls join() after it has finished execution. This operation is done implicitly. The parent process waits until the child joins and continues later.

The join() call breaks the concurrency because the child process exits. The join() inform the parent that child operation is finished.

There are two join scenarios:

  1. The child joins first and then the parent joins without waiting for any process.
  2. The parent process joins first and wait, the child process joins, and the parent continues thereafter.

Example #1

The parent executes “fork L” statement. It creates a child process which runs concurrently- one process (parent) continues after the fork operation and other (child) statement runs at statement labeled L.


fork L;

S2     /* Statement right after fork operation */



L: S3     /* statement labeled L */
Fork-Join Precedence Graph
Figure 1 – Fork-Join Precedence Graph

The fork splits the single operation into two independent operation – S2 and S3.

The join call combines the two concurrent process into one. The process which executes join first will be terminated and the other process continues. If it is parent S2 that terminates first, then it will wait for S3 to finish.

Join () Precedence Graph
Figure 2 – Join () Precedence Graph

If S3 join first, then S2 will join later after finishing the execution without waiting.


Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.