In linux

The clone system call

In Linux there are two system calls to create a child process:

  • fork – creates a new process that is a full copy of the current one.

    • the address space and I/O context are duplicated.

    • the child starts execution in the point of the forking.

  • clone – creates a new process that can share elements with its parent.

    • address space, table of file descriptors, and table of signal handlers are shareable.

    • the child starts execution in a specified function.

Thus, from the kernel point of view, processes and threads are treated similarly.

Threads of the same process forms a thread group and have the same thread group identifier (TGID).

  • this is the value returned by system call getpid().

Within a group, threads can be distinguished by their unique thread identifier (TID).

  • this value is returned by system call gettid().

Thread creation and termination

pthread library

Example

Last updated