- Mastering Linux Kernel Development
- Raghu Bharadwaj
- 193字
- 2021-07-08 09:47:19
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;
- AWS Serverless架構(gòu):使用AWS從傳統(tǒng)部署方式向Serverless架構(gòu)遷移
- Java性能權(quán)威指南(第2版)
- Easy Web Development with WaveMaker
- QTP自動(dòng)化測(cè)試進(jìn)階
- Flux Architecture
- 編程數(shù)學(xué)
- Getting Started with Greenplum for Big Data Analytics
- ASP.NET開(kāi)發(fā)與應(yīng)用教程
- Android高級(jí)開(kāi)發(fā)實(shí)戰(zhàn):UI、NDK與安全
- WCF編程(第2版)
- Learn C Programming
- Visual FoxPro數(shù)據(jù)庫(kù)程序設(shè)計(jì)
- Unity虛擬現(xiàn)實(shí)開(kāi)發(fā)圣典
- 深度學(xué)習(xí)的數(shù)學(xué):使用Python語(yǔ)言
- Java項(xiàng)目驅(qū)動(dòng)開(kāi)發(fā)教程