Linux select函数

select会被信号量中断,比如SIGINT

#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>

int s_runflag = 1;

void sig_int(int sig)
{
    printf("signal int[%d]\n", sig);
}

void sig_quit(int sig)
{
    printf("signal quit[%d]\n", sig);
    s_runflag = 0;
}

int main()
{
    int fd = open("./1.txt", O_CREAT);
    signal(SIGINT, sig_int);
    signal(SIGQUIT, sig_quit);
    while(s_runflag)
    {
        printf("before select\n");
        select(fd+1, NULL, NULL, NULL, NULL);
        printf("after select\n");
    }
    return 0;
}

运行结果

before select
^Csignal int[2]
after select
before select
^\signal quit[3]
after select
上一篇:python中random(numpy.random)随机数的使用


下一篇:java单例模式(饿汉&懒汉)