- 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;
- 高效微控制器C語言編程
- Instant Apache Stanbol
- Vue.js 2 and Bootstrap 4 Web Development
- Scala Design Patterns
- 區(qū)塊鏈架構(gòu)與實現(xiàn):Cosmos詳解
- iOS開發(fā)實戰(zhàn):從零基礎(chǔ)到App Store上架
- WSO2 Developer’s Guide
- Internet of Things with Intel Galileo
- Elasticsearch for Hadoop
- BIM概論及Revit精講
- Active Directory with PowerShell
- 零基礎(chǔ)學(xué)Java第2版
- 城市信息模型平臺頂層設(shè)計與實踐
- 循序漸進(jìn)Vue.js 3前端開發(fā)實戰(zhàn)
- 菜鳥成長之路