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

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

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 1613 | 回復(fù): 3
打印 上一主題 下一主題

請(qǐng)幫忙看一下這個(gè)Linux進(jìn)程通信的問(wèn)題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-12-12 22:24 |只看該作者 |倒序?yàn)g覽
這個(gè)程序就是要父進(jìn)程創(chuàng)建兩個(gè)子進(jìn)程,其中一個(gè)執(zhí)行l(wèi)s,另一個(gè)執(zhí)行ps,但保證先執(zhí)行ps,再執(zhí)行l(wèi)s
  1. #include <stdio.h>
  2. #include <wait.h>
  3. #include <unistd.h>
  4. #include <signal.h>
  5. #include <stdlib.h>
  6. #include <sys/types.h>

  7. int main(int argc, char *argv[])
  8. {
  9.         int pid1, pid2;
  10.         int status;
  11.         char *ls_argv[] = {"/bin/ls", "-a", 0};
  12.         char *ps_argv[] = {"/bin/ps", "-l", 0};       

  13.         pid1 = fork();        //create one child process
  14.        
  15.         if(pid1 < 0){
  16.                 printf("Create process fail!\n");
  17.                 exit(EXIT_FAILURE);
  18.         }
  19.         if(pid1 == 0){     //The first child process
  20.                 printf("I'm the first child! I'm waiting for another.\n");
  21.                 pause();
  22.                 printf("I'm going to run ls!\n");
  23.                 execv("/bin/ls", ls_argv);
  24.         }
  25.         else{        //parent process
  26.                 printf("I'm parent. I will create another process.\n");
  27.                 pid2 = fork();
  28.                 if(pid2 == 0){    //The second child process
  29.                         printf("I'm the second process! I will do ps!\n");
  30.                         execv("/bin/ps", ps_argv);
  31.                 }
  32.                 else{      //parent process
  33.                         waitpid(pid2, &status, 0);
  34.                         printf("The second process exit status = %d\n", status);
  35.                         printf("I will arouse my first child!\n");
  36.                         kill(pid1, SIGCONT);
  37.                         waitpid(pid1, &status, 0);
  38.                         printf("The first process exit status = %d\n", status);
  39.                 }
  40.         }
  41.         exit(0);
  42. }       
復(fù)制代碼
邏輯上我覺(jué)得沒(méi)有問(wèn)題,但運(yùn)行時(shí)就卡在kill(pid1, SIGCONT)那里了,根本沒(méi)發(fā)送信號(hào),希望大家?guī)兔φ乙幌率悄睦锏膯?wèn)題,多謝!

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2010-12-13 09:11 |只看該作者
回復(fù) 1# jiakeyouwe


    是因?yàn)樵?pid1 的進(jìn)程中沒(méi)有設(shè)置信號(hào)捕捉。它默認(rèn)應(yīng)該是屏蔽了你發(fā)送的 SIGCONT 這個(gè)信號(hào)的。在pid1中 signal 就好了。

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2010-12-13 11:04 |只看該作者
2樓正解

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2010-12-14 20:12 |只看該作者
回復(fù) 2# linyunxian


    恩,解決了 謝謝!
您需要登錄后才可以回帖 登錄 | 注冊(cè)

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP