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

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;
主站蜘蛛池模板: 涟水县| 永宁县| 琼中| 广安市| 吴桥县| 忻州市| 当阳市| 焉耆| 巴彦县| 于田县| 陆良县| 祁东县| 竹北市| 巨鹿县| 神木县| 临泽县| 南投市| 平凉市| 皮山县| 洱源县| 东阿县| 仙居县| 镇远县| 金寨县| 鹿邑县| 馆陶县| 高阳县| 灵宝市| 吴川市| 同心县| 樟树市| 辽宁省| 宁陕县| 石柱| 明星| 大余县| 山丹县| 吕梁市| 平湖市| 尼勒克县| 越西县|