⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sigrecv.c

📁 linux父子进程间关系
💻 C
字号:
#include <stdio.h>#include <signal.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <string.h>#define M 2void sighdlr(int signum);int main(){       pid_t a;    signal(SIGUSR1, sighdlr);    signal(SIGUSR2, sighdlr);    a=getpid();    printf("My pid is %d.\n",a);    while(1);    return 0;}void sighdlr(int signum){    int fd0,fd1;    int success;	     char s[M];    switch (signum)     {       case SIGUSR1:           printf("Recived SIGUSR1\n");           exit(0);       break;       case SIGUSR2:           printf("Recived SIGUSR2\n");	   if ((fd0 = open("temp.txt", O_RDONLY)) < 0)               {  	            write(STDERR_FILENO, "open file Error!\n",sizeof("open file Error!\n"));  	            exit(1);               }           mkfifo("test.txt",0777);           if ((fd1 = open("test.txt", O_WRONLY)) < 0)               {                    write(STDERR_FILENO, "open fifo file Error!\n",sizeof("open file Error!\n"));                    exit(1);               }           success=read(fd0,s,M);           while(success>0)           {               write(fd1,s,strlen(s));               success=read(fd0,s,M);           }           close(fd0);           close(fd1);       break;       default:           break;    }}

⌨️ 快捷键说明

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