相关疑难解决方法(0)

c ++ fork,无需等待,解散execl

希望在c ++中分叉一个不会挂起其父进程的进程 - 它的父进程是守护进程并且必须保持运行.如果我在分叉进程上等待(),分叉的execl将不会分流 - 但是 - 它也会挂起应用程序 - 而不是等待修复应用程序挂起 - 但命令变得无法解决.

if((pid = fork()) < 0)
    perror("Error with Fork()");
else if(pid > 0) { 
    //wait here will hang the execl in the parent
    //dont wait will defunt the execl command 
    //---- wait(&pid);
    return "";
} else {
    struct rlimit       rl;
    int                 i;

    if (rl.rlim_max == RLIM_INFINITY)
        rl.rlim_max = 1024;

    for (i = 0; (unsigned) i < rl.rlim_max; i++)
        close(i);

    if(execl("/bin/bash", "/bin/bash", "-c", "whoami", (char*) 0) < 0) perror("execl()");
    exit(0); …
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
3815
查看次数

标签 统计

c++ ×1