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

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;
主站蜘蛛池模板: 都昌县| 轮台县| 丰都县| 涿鹿县| 夏津县| 天全县| 余庆县| 承德市| 涞源县| 台北市| 繁峙县| 二连浩特市| 湖南省| 卫辉市| 济源市| 平和县| 冀州市| 永平县| 抚州市| 黔西| 涿州市| 新巴尔虎左旗| 黔东| 朝阳县| 宁津县| 林西县| 资讯 | 神农架林区| 阳春市| 建湖县| 金川县| 永年县| 邵武市| 浠水县| 仁布县| 裕民县| 本溪市| 濉溪县| 卓资县| 威宁| 海兴县|