是否有等效于 macOS 上的 clone() 系统调用?
Is there an equivalent to the clone() syscall on macOS?
作为Linux中的那个,我可以在其中传递要在子项中执行的函数,要使用的内存等作为参数。我附上一个示例,其中我正在尝试启动一个子进程,该子进程将使用stack_memory()
中分配的内存执行chld_func
函数。
#include <iostream>
#include <sched.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
// ...
int main(int argc, char** argv)
{
printf("Hello, World! (parent)n");
clone(chld_func, stack_memory(), SIGCHLD, 0);
wait(nullptr);
return EXIT_SUCCESS;
}
也许我可以尝试使用fork()
做类似的事情,但我不知道从哪里开始。
提前感谢!
正如这里和这里所说clone
特定于Linux。
您可以执行的macOS系统调用包括fork
和vfork
,因此您可以使用其中之一。
另请参阅此答案,了解有关clone
和fork
以及读取手册页的一些推理:
- http://man7.org/linux/man-pages/man2/clone.2.html
- http://man7.org/linux/man-pages/man2/vfork.2.html
- http://man7.org/linux/man-pages/man2/fork.2.html
相关文章:
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 如果整个应用程序是虚拟映射的,为什么 new 会进行系统调用?
- 如何将C++系统调用连接到 freertos
- 如何使用 C/C++ 和 system() 系统调用以外的其他方法在 Linux 中获取文件功能?
- 系统调用:一次和多次,哪个更好?
- 使用路径和空格的系统调用
- 是否有等效于 macOS 上的 clone() 系统调用?
- 从C++调用系统调用节点?
- C++测试程序中的非法系统调用(对角矩阵元素程序的总和)
- 英特尔 Pin:如何获取系统调用的返回地址
- 如何使用低级系统调用从 stdin 和输入文件中获取字节数
- 使用模拟器C++从RISC-V裸机程序调用printf系统调用时失败
- 动态执行的 ARM ASM 系统调用,可从C++重新定位
- 如何知道我正在使用的Linux OS是否具有特定的系统调用
- 当C 中的系统调用conconculables时,参数字符串中的字符损失
- 调用系统调用函数时出现异常
- 在 boost::asio 中自定义套接字/关闭系统调用
- 系统调用失败"Incorrect Section Name -e" C++
- 绕过系统调用 C++
- 以非 root 用户身份调用 mount() 系统调用