簡體   English   中英

為什么子進程的最后一行不打印?

[英]Why doesn't the last line of the child process print?

#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>


int main( ) {
    pid_t pid;
    int status = -1; 

    if ((pid = fork()) != 0) {
       printf("Father process wait child PID=%d\n", pid);
       wait(&status);
       printf("Child finish with status: %d\n",WEXITSTATUS(status));
       exit(0);
    }
    else {
       printf("Child process running...\n");
       execl("/bin/ls","ls", "-la", NULL);
       printf("Child ending...\n");
    }
}

編譯此代碼時,else 的最后一行不打印,我不知道為什么。

http://linux.die.net/man/3/execl

exec() 系列函數用新的進程映像替換當前進程映像。 ....

返回值

exec() 函數僅在發生錯誤時返回。 返回值為-1,設置errno 表示錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM