Linux clone () function

Source: Internet
Author: User
Tags signal handler

Int clone (INT (* fN) (void *), void * child_stack, int flags, void * Arg );

Here FN is the function pointer. We know the four elements of the process. This is the pointer to the program, which is the so-called "script ", child_stack obviously allocates system stack space for sub-processes (in Linux, the system stack space is 2 pages, that is, 8 KB of memory. In this memory, values are placed on the low address, this value is the value of the process control block task_struct). Flags is the identifier used to describe the resources that you need to inherit from the parent process. Arg is the parameter passed to the child process ). The following are values that flags can fetch.

Logo meaning

The parent process of the child process created by clone_parent is the parent process of the caller. The new process and the process that created it become "brother" rather than "Parent and Child"

The clone_fs sub-process shares the same file system with the parent process, including root, current directory, and umask

The clone_files sub-process shares the same file descriptor with the parent process.

Clone_newns in the new namespace promoter process, namespace describes the process File hierarchy

The clone_sighand sub-process shares the same signal processing (signal handler) table with the parent process.

Clone_ptrace if the parent process is traced, the child process is also traced

The clone_vfork parent process is suspended until the child process releases virtual memory resources.

Clone_vm sub-processes and parent processes run in the same memory space

When the clone_pid sub-process is created, the PID is consistent with the parent process.

Added in clone_thread Linux 2.4 to support POSIX thread standards. The sub-process shares the same thread group with the parent process.

The following example creates a thread (the child process shares the virtual memory space of the parent process and cannot be called a process without its own virtual memory space ). The parent process is suspended. When the sub-thread releases the virtual memory resource, the execution continues.

The fork function is similar to the system call clone function, but the fork function is actually only part of the clone function. The main difference between clone and fork is that several parameters are passed, the most important parameter is conle_flags. The following table lists the clone_flags defined by the system:
Mark Value Meaning
Clone_vm 0x00000100 set this flag to share the address space between processes
Clone_fs 0x00000200 enable this flag to share file system information between processes
Clone_files 0x00000400 set this flag to share opened files between processes
Clone_sighand 0x00000800 set this flag to share the signal handler between processes
If the above flag is set, the processing is as follows:
Set the clone_vm flag:

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/haiyan0106/archive/2007/11/19/1891907.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.