读文件时收到信号,read函数部分成功

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#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函数部分成功_第1张图片

你可能感兴趣的:(linux)