簡體   English   中英

fork()阻止父進程

[英]fork() blocks the father's process

我正在嘗試使用fork()以非阻塞方式在程序中運行程序。

pid = fork();

//check for errors
if (pid < 0) {
    exit(1);
}

//the child process runs the gulp
if (pid == 0) {
    if (execv("/home/gulpSniffer/programname", args) < 0) {
        exit(1);
    }
    //child is supposed to block here
}

//father is supposed to continue its run from here

但是,在子進程中調用程序會阻塞整個程序,並且父進程的代碼段不會被執行,因為它被子進程阻止。

有誰知道為什么?

謝謝

您是否wait子進程在父進程中終止? 這將阻止孩子實際終止。

或者你可能有自己的SIGCHLD信號處理程序,它以某種方式阻塞?

想不出孩子可以制作父塊的任何其他方式(好吧,除了任何進程間鎖定機制,但你會知道你是否使用過這些)。

此外,如果你不關心子進程何時結束,你應該設置

signal(SIGCHLD, SIG_IGN);

這樣系統應該自動收獲退出的孩子,而你最終不會得到僵屍。

暫無
暫無

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

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