#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#define BUF_SIZE (1024*1024)
char buf[BUF_SIZE];
void sig_handler(int sig)
{
printf("signal %d\n", sig);
return;
}
int main(int argc, char * argv[])
{
int fd ;
ssize_t len;
signal(30, sig_handler);
fd = open("/dev/zero", O_RDONLY);
if (fd < 0) {
printf("open fail: %d\n", errno);
return -1;
}
while (1) {
len = read(fd, buf, BUF_SIZE);
if (len < BUF_SIZE) {
printf("read %ld bytes\n", len);
}
}
return 0;
}
读文件时收到信号,read函数部分成功
最新推荐文章于 2024-08-05 09:53:53 发布