使用sigset()在C中创建后台进程

时间:2016-02-12 05:04:26

标签: c unix process

我在C中创建自己的shell。这是我运行进程的基本代码:

pid_t childpid;
int status;
int ret = 0;

if (strcmp(line[0], "exit") == 0) {
    return;
}
childpid = fork();
if (childpid >= 0) {
    if (childpid == 0) {
        ret = execvp(line[0], &line[0]);
        if (ret == -1) {
            printf("ERROR\n");
            exit(0);
        }
        exit(ret);
    } else {
        waitpid(childpid, &status, 0);
        ret = WEXITSTATUS(status);
    }
} else {
    perror("fork");
    exit(-1);
}

line是"字符串数组"按住命令运行。

现在说我要运行后台进程 - 我必须使用sigset。父母不等待背景儿童过程,对吗?如果孩子不成为后台流程,我该如何处理?

0 个答案:

没有答案