<div dir="ltr">I write a c source file, and test in my machine. At the beginning, the fd is writable when the fd is open but the process doesn't receive the SIGIO. so i'm confused a lot of paper or books say that the process will receive SIGIO when the fd is writable or readable. but in fact it doesn't. so any idea? <div><br><div><div>#include<stdio.h></div><div>#include<string.h></div><div>#include<sys/types.h></div><div>#include<stdlib.h></div><div>#include<unistd.h></div><div>#include<sys/socket.h></div><div>#include<fcntl.h></div><div>#include <sys/ioctl.h></div><div>#include<signal.h></div><div>#include<string.h></div><div><br></div><div><br></div><div>void ngx_signal_handler(int signo, siginfo_t *siginfo, void *ucontext){</div><div>    printf("%d\n", signo);</div><div>}</div><div><br></div><div>int main()</div><div>{</div><div>    int sv[2];</div><div>    if(socketpair(PF_LOCAL,SOCK_STREAM,0,sv) < 0)</div><div>    {</div><div>        perror("socketpair");</div><div>        return 0;</div><div>    }</div><div>    struct sigaction sa;</div><div><br></div><div>    memset(&sa, 0, sizeof(struct sigaction));</div><div><br></div><div>    sa.sa_sigaction = ngx_signal_handler;</div><div>    sa.sa_flags = SA_SIGINFO;</div><div><br></div><div>    sigaction(SIGIO, &sa, NULL);</div><div><br></div><div>    pid_t id = fork();</div><div>    if(id == 0) </div><div>    {</div><div><br></div><div>        close(sv[0]);</div><div><br></div><div>        const char* msg = "i'm child\n";</div><div>        char buf[1024];</div><div>        while(1)</div><div>        {</div><div>            /*write(sv[1],msg,strlen(msg));*/</div><div>            sleep(1);</div><div><br></div><div>            /*ssize_t _s = read(sv[1],buf,sizeof(buf)-1);*/</div><div>            /*if(_s > 0)*/</div><div>            /*{*/</div><div>            /*    buf[_s] = '\0';*/</div><div>            /*    printf(" %s\n",buf);*/</div><div>            /*}*/</div><div>        }</div><div>    }</div><div>    else   //father</div><div>    {</div><div>        close(sv[1]);</div><div>        const char* msg = "i'm father\n";</div><div>        char buf[1024];</div><div>        int on = 1;</div><div>        if (ioctl(sv[0], FIOASYNC, &on) == -1) {</div><div>            return 1;</div><div>        }</div><div><br></div><div>        if (fcntl(sv[0], F_SETOWN, getpid()) == -1) {</div><div>            return 1;</div><div>        }</div><div>        while(1){</div><div><br></div><div>            /*ssize_t _s = read(sv[0],buf,sizeof(buf)-1);*/</div><div>            /*if(_s > 0)*/</div><div>            /*{*/</div><div>            /*    buf[_s] = '\0';*/</div><div>            /*    printf(" %s\n",buf);*/</div><div>            /*    sleep(1);*/</div><div>            /*}*/</div><div>            /*write(sv[0],msg,strlen(msg));*/</div><div>        }</div><div>    }</div><div>    return 0;</div><div>}</div></div><div><br></div></div></div>