官术网_书友最值得收藏!

clone()

clone() is a Linux-specific system call to create a new process; it is considered a generic version of the fork() system call, offering finer controls to customize its functionality through the flags argument:

int clone(int (*child_func)(void *), void *child_stack, int flags, void *arg);

It provides more than twenty different CLONE_* flags that control various aspects of the clone operation, including whether the parent and child process share resources such as virtual memory, open file descriptors, and signal dispositions. The child is created with the appropriate memory address (passed as the second argument) to be used as the stack (for storing the child's local data). The child process starts its execution with its start function (passed as the first argument to the clone call).

When a process attempts to create a thread through the pthread library, clone() is invoked with the following flags:

/*clone flags for creating threads*/
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID;

The clone() can also be used to create a regular child process that is normally spawned using fork() and vfork():

/* clone flags for forking child */
flags = SIGCHLD;
/* clone flags for vfork child */
flags = CLONE_VFORK | CLONE_VM | SIGCHLD;
主站蜘蛛池模板: 会宁县| 石渠县| 沧州市| 晋州市| 沈丘县| 兰溪市| 海阳市| 定结县| 姜堰市| 商丘市| 施甸县| 武平县| 许昌县| 济阳县| 凤冈县| 玉溪市| 靖州| 龙山县| 宜宾县| 库尔勒市| 西平县| 巴塘县| 蕉岭县| 江都市| 迁安市| 定襄县| 成安县| 麦盖提县| 贵定县| 黔西县| 宁化县| 定兴县| 钟山县| 阳春市| 讷河市| 湟中县| 樟树市| 三河市| 安龙县| 涿州市| 咸丰县|