A signal was received while reading the file, and the read function was partially successful.

#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;
}

Signal received during read, partially successful

Guess you like

Origin blog.csdn.net/konga/article/details/102693336