Difference between fork(), clone().

What is the difference between fork(), clone(), and pthread_create() system calls.?

Answer:

Excepts from the manpage:++

clone() creates a new process, in a manner similar to fork(). It is actually a library function layered on top of the underlying clone() system call, hereinafter referred to as sys_clone.

Unlike fork(), these calls allow the child process to share parts of its execution context with the calling process, such as the memory space, the table of file descriptors, and the table of signal handlers.

The main use of clone() is to implement threads: multiple threads of control in a program that run concurrently in a shared memory space.

When the child process is created with clone(), it executes the function application fn(arg). (This differs from fork(), where execution continues in the child from the point of the fork() call.) The fn argument is a pointer to a function that is called by the child process at the beginning of its execution. The arg argument is passed to the fn function.

See also:[2]

No comments: