- 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;
- JBoss Weld CDI for Java Platform
- 深度強化學習算法與實踐:基于PyTorch的實現
- Jenkins Continuous Integration Cookbook(Second Edition)
- 速學Python:程序設計從入門到進階
- Extreme C
- 青少年學Python(第2冊)
- Drupal 8 Development Cookbook(Second Edition)
- Mastering Machine Learning with R
- ASP.NET Core and Angular 2
- JSP應用與開發技術(第3版)
- Implementing Splunk(Second Edition)
- 瘋狂Ajax講義(第3版)
- 給產品經理講技術
- Visual FoxPro程序設計教程(第3版)
- jMonkeyEngine 3.0 Cookbook