亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2548 | 回復(fù): 5
打印 上一主題 下一主題

[其他] 為什么父進(jìn)程在為子進(jìn)程改變進(jìn)程組ID時(shí),子進(jìn)程收到了SIGHUP信號昵? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2012-11-09 11:27 |只看該作者 |倒序?yàn)g覽
本帖最后由 DIYBYPERL 于 2012-11-09 12:51 編輯
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4. #include <sys/wait.h>
  5. #include <signal.h>
  6. #include <errno.h>

  7. void signHand(int sign)
  8. {
  9.     printf("pid[%d]sign[%d] received----YHB\n", getpid(), sign);

  10.     if (sign == SIGHUP )
  11.     {      
  12.         printf("register SIGTTIN\n");
  13.         if( signal(SIGTTIN, signHand) == SIG_ERR)
  14.         {      
  15.             printf("Cant register SIG\n");
  16.         }      
  17.     }
  18.     //if (sign == SIGCONT )
  19.     //{     
  20.     //    printf("register SIGCONT\n");
  21.     //    if( signal(SIGCONT, signHand) == SIG_ERR)
  22.     //    {
  23.     //        printf("Cant register SIG\n");
  24.     //    }
  25.     //}
  26. }
  27. int main()
  28. {
  29.     setbuf(stdout,NULL);
  30.     printf("main: %d %d\n", getpid(), getpgrp());
  31.     pid_t pid = fork();
  32.     if(pid <0){
  33.         perror("fork");
  34.         return 1;
  35.     }

  36.     setpgid(pid,0);
  37.     if(pid >0){
  38.         printf("parent begin to 10 seconds\n");
  39.         sleep(10);
  40.         printf("parent let child come back\n");
  41. //------------>為什么父進(jìn)程在為子進(jìn)程改變進(jìn)程組ID時(shí),子進(jìn)程收到了SIGHUP信號昵?
  42.         printf("setpgid[%d][%d][%s]\n", setpgid(pid, getpgrp()), errno, strerror(errno));
  43.         printf("parent begin to 20 seconds\n");
  44.         sleep(20);
  45.         printf("parent let child continue\n");
  46.         kill(pid, SIGCONT);
  47.         printf("parent wait child\n");
  48.         waitpid(pid,NULL,0);
  49.         printf("parent exit\n");
  50.         return 0;
  51.     }

  52.    char buf[1024];
  53.    printf("child: %d %d\n", getpid(), getpgrp());
  54.    if (signal(SIGHUP, signHand) == SIG_ERR)
  55.    {
  56.        printf("Cant register SIG\n");
  57.        return -1;
  58.    }
  59.    if (signal(SIGCONT, signHand) == SIG_ERR)
  60.    {
  61.        printf("Cant register SIG\n");
  62.        return -1;
  63.    }
  64.    while(fgets(buf,1024, stdin)){
  65.         printf("child.PID[%d].PGID[%d]>", getpid(), getpgrp());
  66.         fputs(buf, stdout);
  67.    }
  68.    printf("child exit\n");
  69.    return 0;
  70. }
復(fù)制代碼
編譯后的文件為a
  1. test:/home/test/testc>a
  2. main: 30671002 30671002
  3. child: 13369572 13369572
  4. parent begin to 10 seconds
  5. parent let child come back
  6. setpgid[0][0][Error 0]
  7. parent begin to 20 seconds
  8. pid[13369572]sign[19] received----test
  9. pid[13369572]sign[1] received----test
  10. register SIGTTIN
  11. 12345555555555555555555555555555
  12. child.PID[13369572].PGID[30671002]>12345555555555555555555555555555
  13. parent let child continue
  14. parent wait child
  15. 44444444444444444444444444444444444
  16. child.PID[13369572].PGID[30671002]>44444444444444444444444444444444444
  17. child exit
  18. parent exit
  19. test:/home/test/testc>
復(fù)制代碼
請大俠解釋下。。。。。。。。。。。。。。
環(huán)境是AIX 6.1

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2012-11-09 16:14 |只看該作者
不能沉的。。。。。。

論壇徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46處女座
日期:2013-10-24 14:25:01酉雞
日期:2014-04-07 11:54:15
3 [報(bào)告]
發(fā)表于 2012-11-10 12:38 |只看該作者
樓主AIX很神奇, 我表示怎么分析也分析不出來有理由SIGHUP, 因?yàn)樽舆M(jìn)程不在孤兒進(jìn)程組里.

簡單的注釋了一下, 樓主再分析分析, 看有什么區(qū)別, 反正linux下是和樓主的結(jié)果不同:
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4. #include <sys/wait.h>
  5. #include <signal.h>
  6. #include <errno.h>
  7. #include <string.h>

  8. void signHand(int sign)
  9. {
  10.     printf("pid[%d]sign[%d] received----YHB\n", getpid(), sign);

  11.     if (sign == SIGHUP )
  12.     {      
  13.         printf("register SIGTTIN\n");

  14.         if( signal(SIGTTIN, signHand) == SIG_ERR)
  15.         {      
  16.             printf("Cant register SIG\n");
  17.         }      
  18.     }
  19. }

  20. int main()
  21. {
  22.     setbuf(stdout,NULL);
  23.     printf("main: %d %d\n", getpid(), getpgrp());
  24.    
  25.     pid_t pid = fork();
  26.    
  27.     if(pid < 0) {
  28.         perror("fork");
  29.         return 1;
  30.     }

  31.     //父進(jìn)程將子進(jìn)程的組設(shè)置為子進(jìn)程的pid, 也就是子進(jìn)程新進(jìn)入了一個(gè)進(jìn)程組
  32.     //子進(jìn)程執(zhí)行這句毫無效果, 雖然和父進(jìn)程執(zhí)行有競爭, 但沒有實(shí)際效果, 想到于setpgid(0, 0);
  33.     setpgid(pid, 0);
  34.     printf("pid=%d gid=%d cccc", getpid(), getpgrp());

  35.     if(pid >0) {
  36.         printf("parent begin to 10 seconds\n");
  37.         sleep(2);
  38.         printf("parent let child come back\n");
  39.         //父進(jìn)程又把子進(jìn)程恢復(fù)到父進(jìn)程的進(jìn)程組里
  40.         //但你要知道子進(jìn)程此刻一定是進(jìn)程組長, 一個(gè)進(jìn)程組長離開了進(jìn)程組而已, 并且父進(jìn)程組也不是孤兒組, 沒理由SIGHUP啊
  41.         printf("setpgid[%d][%d][%s]\n", setpgid(pid, getpgrp()), errno, strerror(errno));
  42.         printf("parent begin to 20 seconds\n");
  43.         sleep(2);
  44.         printf("parent let child continue\n");
  45.         kill(pid, SIGCONT);
  46.         printf("parent wait child\n");
  47.         waitpid(pid,NULL,0);
  48.         printf("parent exit\n");
  49.         return 0;
  50.     }

  51.    char buf[1024];
  52.    printf("child: %d %d\n", getpid(), getpgrp());
  53.    if (signal(SIGHUP, signHand) == SIG_ERR)
  54.    {
  55.        printf("Cant register SIG\n");
  56.        return -1;
  57.    }
  58.    if (signal(SIGCONT, signHand) == SIG_ERR)
  59.    {
  60.        printf("Cant register SIG\n");
  61.        return -1;
  62.    }
  63.    //這里你可以看到, 子進(jìn)程的確又回到了父進(jìn)程的組
  64.    while(fgets(buf,1024, stdin)){
  65.         printf("child.PID[%d].PGID[%d]>", getpid(), getpgrp());
  66.         fputs(buf, stdout);
  67.    }
  68.    printf("child exit\n");
  69.    return 0;
  70. }
復(fù)制代碼

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2012-11-12 09:20 |只看該作者
回復(fù) 3# linux_c_py_php
能把你執(zhí)行的結(jié)果貼出來看看么?

我在AIX 執(zhí)行了你的代碼,還是收到了SIGHUP信號:
  1. main: 28377192 28377192
  2. pid=39452678 gid=39452678 ccccchild: 39452678 39452678
  3. pid=28377192 gid=28377192 ccccparent begin to 10 seconds
  4. parent let child come back
  5. setpgid[0][0][Error 0]
  6. parent begin to 20 seconds
  7. pid[39452678]sign[19] received----YHB
  8. pid[39452678]sign[1] received----YHB
  9. register SIGTTIN
  10. parent let child continue
  11. parent wait child
  12. dasfdf
  13. child.PID[39452678].PGID[28377192]>dasfdf
  14. dsafdf
  15. child.PID[39452678].PGID[28377192]>dsafdf
  16. dafds
  17. child.PID[39452678].PGID[28377192]>dafds

  18. child.PID[39452678].PGID[28377192]>
  19. child exit
  20. parent exit
復(fù)制代碼

論壇徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46處女座
日期:2013-10-24 14:25:01酉雞
日期:2014-04-07 11:54:15
5 [報(bào)告]
發(fā)表于 2012-11-12 11:03 |只看該作者
[root@vps616 c]# ./main
main: 27444 27444
pid=27444 gid=27444 ccccparent begin to 10 seconds
pid=27445 gid=27445 ccccchild: 27445 27445
parent let child come back
setpgid[0][0][Success]
parent begin to 20 seconds
parent let child continue
parent wait child
pid[27445]sign[18] received----YHB

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2012-11-12 12:52 |只看該作者
回復(fù) 5# linux_c_py_php

pid[27445]sign[18] received----YHB
18是LINUX下的SIGCONT信號吧?

奇怪的AIX。!
   
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP