• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Prayer

            在一般中尋求卓越
            posts - 1256, comments - 190, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            10.7 SIGCLD semantics

            Posted on 2009-04-14 15:40 Prayer 閱讀(876) 評論(0)  編輯 收藏 引用 所屬分類: LINUX/UNIX/AIX

            10.7 SIGCLD semantics

            SIGCLD是在system v的系列版本中使用的一個信號。SIGCHLDBSD系列版本中使用的信號,他們的意義有所不同,其中SIGCLD應該被禁用。其原因如下:

            () system SIGCLD

            SVR4是從system v發展出來的,它使用SIGCLD的方法(如下都以signalsigset函數作為signal安裝函數)

            1.被推薦的使用SIGCLD的方法

            設置SIGCLDSIG_IGN,這樣生成的孩子process在退出后不會生成zombia

            2.不被推薦的使用方法

            就是默認的對SIGCLD的處理方法,即SIG_DFL,子進程結束后不處理,如果父親wait的話,會等所有的孩子進程結束后才返回-1errno=ECHLD。這不是推薦的。

             

            可見在System v系列里,對SIGCLD的使用推薦使用SIG_IGN

             

            3system vSIGCLD的一個被詬病的地方

            就是當用signal安裝SIGCLDhandler的時候,他會立馬檢查當前是否有孩子進程可以被waited,如果有,就立馬調用handler這會造成stack overflow,例如:我們用signal安裝handler的時候,經常在signal handler里面首先將handler reinstall, 好,當有一個子進程結束了,發送了SIGCLD信號,該handler被調用,reinstall handler, 立馬檢查是否有可以waited的進程,有,立馬調用handler, ….如此循環,不久死掉了么.

            如下就是例子代碼:

            Figure 10.6. System V SIGCLD handler that doesn't work

            #include      "apue.h"

            #include      <sys/wait.h>

             

            static void sig_cld(int);

             

            int

            main()

            {

                pid_t   pid;

             

                if (signal(SIGCLD, sig_cld) == SIG_ERR)

                    perror("signal error");

                if ((pid = fork()) < 0) {

                    perror("fork error");

                } else if (pid == 0) {      /* child */

                    sleep(2);

                    _exit(0);

                }

                pause();    /* parent */

                exit(0);

            }

             

            static void

            sig_cld(int signo)   /* interrupts pause() */

            {

                pid_t   pid;

                int     status;

             

                printf("SIGCLD received\n");

                if (signal(SIGCLD, sig_cld) == SIG_ERR) /* reestablish handler */

                    perror("signal error");

                if ((pid = wait(&status)) < 0)      /* fetch child status */

                    perror("wait error");

                printf("pid = %d\n", pid);

            }

             

            可見system v系列不能給SIGCLD安裝handler,那么就只能采用推薦的方法SIG_IGN了。使其子進程壓根不產生zombia.

             

            (二)SIGCHLD

            linux里,用signal安裝SIGCHLD,且將handler置為SIG_IGN,也會達到是子進程退出后不產生zombia的好處。而默認的我們不處理該信號,就會產生zombiaBSD系列就是這樣。

            如下是摘自linux suse man page的一段話:

            POSIX.1-1990 disallowed setting the action for SIGCHLD to SIG_IGN.  POSIX.1-2001 allows this  possibility, so that ignoring SIGCHLD can be used to prevent the creation of zombies (see wait(2)).  Nevertheless, the historical BSD and System V behaviors for ignoring SIGCHLD differ, so that  the  only  completely  portable  method  of ensuring that terminated children do not become zombies is to catch the SIGCHLD signal and perform a wait(2) or similar.

            鑒于不同平臺的對SIGCHLD的設置成SIG_IGN的意義的不同,唯一的更portable的避免zombia的方法是在SIGCHLDhandler里面調用wait

            (三)使不產生zombia孩子的另一個方法

            使用sigaction并設置SA_NOCLDWAIT標記

             

            (四)在包括linux在內的一些平臺,SIGCLD被宏定為SIGCHLD,放心使用

             

            久久棈精品久久久久久噜噜| 久久九九久精品国产| 伊人久久大香线蕉成人| 一级a性色生活片久久无少妇一级婬片免费放 | 久久免费的精品国产V∧| 国产亚洲欧美成人久久片| 伊人丁香狠狠色综合久久| 伊人久久一区二区三区无码| 亚洲AV无码久久精品色欲| 亚洲伊人久久大香线蕉苏妲己| 久久久久无码中| 久久精品一区二区三区不卡| 久久久久九九精品影院| 欧美熟妇另类久久久久久不卡 | 久久精品国产精品亚洲精品| 久久99热国产这有精品| 波多野结衣久久一区二区| 91亚洲国产成人久久精品| 久久婷婷五月综合97色| 欧美日韩精品久久久久| 国产成人香蕉久久久久| 性欧美丰满熟妇XXXX性久久久| 久久久久18| 精品久久久久一区二区三区| 国产精品久久午夜夜伦鲁鲁| 久久天天躁夜夜躁狠狠| 亚洲欧美日韩精品久久亚洲区 | 国产成人精品久久| 91精品国产综合久久婷婷| 色偷偷88888欧美精品久久久| 日本国产精品久久| 精品久久久久中文字| 国产精品热久久毛片| 久久久久久久综合日本亚洲| 国产精品无码久久久久久| 麻豆亚洲AV永久无码精品久久| 日本五月天婷久久网站| 久久综合九色综合网站| 久久人人爽人人爽人人片AV不| 亚洲精品tv久久久久| 亚洲国产成人久久精品99|