[Overview][Constants][Types][Procedures and functions][Index] Reference for unit 'Linux' (#rtl)


Clone current process (create new thread)


Source position: linux.pp line 224

function clone(

  func: TCloneFunc;

  sp: pointer;

  flags: LongInt;

  args: pointer



Clone creates a child process which is a copy of the parent process, just like FpFork does. In difference with Fork, however, the child process shares some parts of it's execution context with its parent, so it is suitable for the implementation of threads: many instances of a program that share the same memory.

When the child process is created, it starts executing the function Func, and passes it Args. The return value of Func is either the explicit return value of the function, or the exit code of the child process.

The sp pointer points to the memory reserved as stack space for the child process. This address should be the top of the memory block to be used as stack.

The Flags determine the behaviour of the Clone call. The low byte of the Flags contains the number of the signal that will be sent to the parent when the child dies. This may be bitwise OR'ed with the following constants:

Parent and child share the same memory space, including memory (un)mapped with subsequent mmap calls.
Parent and child have the same view of the file system; the chroot, chdir and umask calls affect both processes.
the file descriptor table of parent and child is shared.
the parent and child share the same table of signal handlers. The signal masks are different, though.
Parent and child have the same process ID.

Clone returns the process ID in the parent process, and -1 if an error occurred.


On error, -1 is returned to the parent, and no child is created.

Too many processes are running.
Not enough memory to create child process.

See also



Create child process

Documentation generated on: May 14 2021