由于某些我不知道的原因,我唯一的第一条execl语句正在以下代码中执行:

pid = fork();
if(pid < 0){
    fprintf(stderr, "Fork Failed.\n");
    exit(1);
    return;
}else if(pid==0){
        if(execl("/home/tropix/hw11-2","/home/tropix/hw11-2",semarg,pipe_to_p3,pipe_to_p4,(char*)0)){
            fprintf(stderr, "File Exexecution of hw11-2 failed.\n");
            exit(1);
        }
        if(execl("/home/tropix/hw11-3","/home/tropix/hw11-3",shmarg,semarg,pipe_from_p2,pipe_to_p5_1, (char*)0)){
            fprintf(stderr, "File Execution of hw11-3 failed.\n");
            exit(1);
        }
        if(execl("/home/tropix/hw11-4","/home/tropix/hw11-4",shmarg,semarg,pipe_from_p2_2,pipe_to_p5_2, (char*)0)){
            fprintf(stderr, "File Execution of hw11-4 failed.\n");
            exit(1);
        }
        if(execl("/home/tropix/hw11-5","/home/tropix/hw11-5",semarg,pipe_from_p3,pipe_from_p4,(char*)0)){
            fprintf(stderr, "File Execution of hw11-5 failed.\n");
            exit(1);
        }
} else (...parent stuff...)

有人知道这是为什么吗?
谢谢:)

最佳答案

The exec family of functions shall replace the current process image with a new process image.
因此,在第一execl之后,第二根本不存在。

关于c - execl在派生过程中仅执行一次,C编程,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5930967/

10-16 13:51