更多资料请点击:我的目录
本篇仅用于记录自己所学知识及应用,代码仍可优化,仅供参考,如果发现有错误的地方,尽管留言于我,谢谢。
输出结果:
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#define SIZE 1024
int main(int argc, char **argv)
{
//检测输入参数是否正确
if(argc != 2)
{
perror("输入错误!\n");
exit(0);
}
long src[SIZE], i = 0;
while(1)
{
//open()系统IO打开指定的文件(只读),读取成功src[i] >= 0
src[i] = open(argv[1], O_RDONLY);
if ( src[i] == -1 )//读取失败src[i] = -1
{
//strerror(errno)输出错误信息
printf("Error:%s\n当前系统的进程最多能打开%ld个文件。\n",strerror(errno),i);
exit(0);
}
i++;
}
return 0;
}
更多资料请点击:我的目录