更多資料請點擊:我的目錄
本篇僅用於記錄自己所學知識及應用,代碼仍可優化,僅供參考,如果發現有錯誤的地方,儘管留言於我,謝謝。
輸出結果:
#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;
}
更多資料請點擊:我的目錄