• <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++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
            /*編制一段程序,使用系統(tǒng)調(diào)用fork()創(chuàng)建兩個(gè)子進(jìn)程,
            再用系統(tǒng)調(diào)用signal()讓父進(jìn)程捕捉鍵盤上來的中斷信號(hào)(即按Del鍵),
            當(dāng)捕捉到中斷信號(hào)后,父進(jìn)程用系統(tǒng)調(diào)用kill()向兩個(gè)子進(jìn)程發(fā)出信號(hào),
            子進(jìn)程捕捉到信號(hào)后,分別輸出下列信息后終止:
                child process 1 is killed by parent!
                child process 2 is killed by parent!
                父進(jìn)程等待兩個(gè)子進(jìn)程終止后,輸出以下信息后終止:
                parent process is killed !
            */
            #include<stdio.h>
            #include<signal.h>
            #include<unistd.h>
            void waiting();
            void stop();
            int wait_mark;
            main()
            {
                int p1=-1, p2=-1;
                //signal(SIGINT, stop); // position A
                while ((p1 = fork()) == -1);
                    if (p1>0)
                   {   /*parent*/
                       while ((p2 = fork()) == -1);
                       if (p2>0)
                      {   /*parent*/
                          wait_mark=1;
                          signal(SIGINT, stop);// position B
                          waiting();
                          kill(p1,16);             //*send signal 16 to end the process p1
                          kill(p2,17);            //*send signal 17 to end the process p2
                          wait(0);                 //*waiting for the ending of p1
                          wait(0);                //*waiting for the ending of p2
                          printf("parent process is killed!\n");
                          exit(0);                //*quit from the parent process
                      }
                       else                                    //*p2 work
                      {    /*child p2*/
                           wait_mark=1;
                           signal(17, stop);
                           waiting();
                           lockf(1,1,0);
                           printf("child process 2 is killed by parent!\n");
                           lockf(1,0,0);
                        exit(0);                          //* p2  quit
                      }
                   }
                   else                                       //*p1 work
                   {      /*child p1*/
                          wait_mark=1;
                          signal(16, stop);         
                          waiting();
                          lockf(1,1,0);                          
                          printf("child process 1 is killed by parent!\n");
                          lockf(1,0,0);                          
                          exit(0);                           //* p1 quit
                 }
            }

            void waiting( )
            {
                  while (wait_mark != 0);
            }

            void stop()
            {
                  wait_mark=0;
            }


            又研究了一下,在兩個(gè)子進(jìn)程開始就加入signal(SIGINT,SIG_IGN),就滿足要求了。看來原來的Ctrl-c信號(hào)對所有進(jìn)程都起作用了,所以得把它給禁了,才能合要求。   
            很黄很污的网站久久mimi色| 久久精品亚洲欧美日韩久久| 久久天天躁狠狠躁夜夜不卡| 色偷偷91久久综合噜噜噜噜 | 一本久久a久久精品综合香蕉| 青青草原综合久久大伊人| 亚洲欧洲中文日韩久久AV乱码| 18禁黄久久久AAA片| 色综合久久无码中文字幕| 91久久精品视频| 精品国产乱码久久久久久呢| 亚洲国产二区三区久久| 色诱久久av| 一本大道加勒比久久综合| 亚洲色欲久久久综合网| 精品国产乱码久久久久久浪潮| 久久这里都是精品| 久久久久久国产精品无码下载| 久久精品www人人爽人人| 欧洲性大片xxxxx久久久| 99热成人精品热久久669| 久久亚洲精品成人无码网站| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 亚洲欧美另类日本久久国产真实乱对白 | 91性高湖久久久久| 亚洲香蕉网久久综合影视 | 久久国产精品99久久久久久老狼| 色天使久久综合网天天| 久久av高潮av无码av喷吹| 日韩亚洲欧美久久久www综合网| 欧美精品久久久久久久自慰| 久久精品日日躁夜夜躁欧美| 久久精品国产精品亚洲人人 | 久久免费国产精品一区二区| 青草国产精品久久久久久| 久久99久久99精品免视看动漫| 亚洲国产成人精品女人久久久| 亚洲欧美成人久久综合中文网| 99久久综合狠狠综合久久| 久久久久国产成人精品亚洲午夜| 日韩一区二区久久久久久|