绕过系统调用c++

bypass system call c++

我正在编写一个类似这样的 C++ 函数:

while(true){
 function A()
 system(cmd)
 function B()
}

我在两个函数之间进行系统调用,这个系统调用需要很长时间才能执行。有没有可能让它运行在后台绕过它同时执行函数B?

在Linux/Unix、system uses a shell for running cmd. This means, you can append an ampersand &到运行后台命令,例如

const char cmd[] = "some_command &";
while(true){
    functionA();
    system(cmd);
    functionB();
}

请注意,由于这是 运行 循环 while (true) {...},您可能会因后台进程过多而导致系统溢出。