非阻塞型通信进程

#include"stdio.h"  
#include"sys/types.h"  
#include"unistd.h"  
#include"signal.h"  
void sigint_handler(int sig)  
{  
    printf("recevied SIGINT signal successed!\n");  
    return;  
}  
void main()  
{  
    int pid=fork();  
    if(pid==0)  
    {  
        printf("子进程pid: %d\n", getpid());  
        sleep(2);  
        printf("休眠后的pid:%d\n",getpid());  
        sleep(2);  
        printf("第二次休眠后的pid:%d\n",getpid());  
        exit(1);  
    }  
    else if(pid>0)  
    {  
        signal(SIGCHLD, sigint_handler);  
        pause();  
    }  
    else if(pid<0)  
    {  
        printf("创建进程出错!\n");  
        exit(1);      
    }  
}  

 

posted @ 2014-08-10 10:03  商商-77  阅读(103)  评论(0编辑  收藏  举报