c – SIGXFSZ是由内核发送的,除非有什么内容打印到stdout?

前端之家收集整理的这篇文章主要介绍了c – SIGXFSZ是由内核发送的,除非有什么内容打印到stdout?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在学习“Unix环境下的高级编程”,并且在第10章的练习11中遇到了问题.

在我的程序中,我将RLIMIT_FSIZE设置为1024.

所以当写入试图超过该限制时,内核应该将SIGXFSZ发送到我的程序.

但我发现SIGXFSZ不发送,除非打印到stdout的东西.

这是我的代码

#include dio.h>
#include 

如果我在代码中注释掉以下行,内核将不会传输SIGXFSZ.

printf("What ever . . . \n");

为什么会这样?提前致谢.

[root@luaDevelopment ex11]# ./myCopy < /root/workspace/AdvanceProgrammingInTheUnixEnvironment.20140627.tar.bz2 >aa.tar.bz2
byteWrite=24,n=100
[root@luaDevelopment ex11]# make
gcc -o myCopy myCopy.c -std=gnu99 -I../../lib/ -L../../lib/ -lch10
[root@luaDevelopment ex11]# ./myCopy < /root/workspace/AdvanceProgrammingInTheUnixEnvironment.20140627.tar.bz2 >aa.tar.bz2
byteWrite=24,n=100
25,File size limit exceeded
[root@luaDevelopment ex11]#
最佳答案
user3693690在本书附录C中找到了答案:

10.11 Under Linux 3.2.0,Mac OS X 10.6.8,and Solaris 10,the signal handler for SIGXFSZ is never called [because the loop exits the program on a short write],but write returns a count of 24 as soon as the file’s size reaches 1,024 bytes. When the file’s size has reached 1,000 bytes under FreeBSD 8.0,the signal handler is called on the next attempt to write 100 bytes,and the write call returns −1 with errno set to EFBIG(‘‘File too big’’). On all four platforms,if we attempt an additional write at the current file offset (the end of the file),we will receive SIGXFSZ and write will fail,returning−1 with errno set to EFBIG.

如果这是Linux内核用来处理SIGXFSZ的方式,那就这样吧,但我觉得这很奇怪.

原文链接:https://www.f2er.com/linux/441083.html

猜你在找的Linux相关文章