sigsend.c

来自「linux父子进程间关系」· C语言 代码 · 共 56 行

C
56
字号
#include <signal.h>#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#define M  4#define MAX  100int main(int argc, char** argv){    int fd0;    int success,count;    char s[M];    if (argc < 2) {        printf("USEAGE: sigsend PID \n");        exit(0);    }    int ipid;    ipid = atoi(argv[1]);    if (ipid <= 0 )     {        printf("pid error!\n");        exit(1);    }    kill(ipid, SIGUSR2);    printf("Send SIGUSR2\n");    //sleep(5);    while ((fd0 = open("test.txt", O_RDONLY)) < 0)         {             if(errno==ENOENT)             {                 sleep(1);                 continue;             }             write(1, "open fifo file Error!\n",sizeof("open file Error!\n"));             exit(1);         }    count=0;    while(count<=MAX)    {        success=read(fd0,s,M);        success=write(1,s,success);        count=count+success;        if(success<=0)            break;    }    kill(ipid,SIGUSR1);    printf("\nSend SIGUSR1\n");    unlink("test.txt");    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?