/*********************************************************************************
|
* Copyright: (C) 2025 LingYun IoT System Studio
|
* All rights reserved.
|
*
|
* Filename: limit.c
|
* Description: This file is setrlimit() example program.
|
*
|
* Version: 1.0.0(10/28/2025)
|
* Author: Guo Wenxue <guowenxue@gmail.com>
|
* ChangeLog: 1, Release initial version on "10/28/2025 10:40:37 AM"
|
*
|
********************************************************************************/
|
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <sys/resource.h>
|
|
int main(void)
|
{
|
struct rlimit limit;
|
|
/* 获取当前限制 */
|
getrlimit(RLIMIT_NOFILE, &limit);
|
printf("Max. fd limite: soft=%ld, hard=%ld\n", limit.rlim_cur, limit.rlim_max);
|
|
/* 修改软限制为最多可打开的文件描述个数(硬限制) */
|
limit.rlim_cur = limit.rlim_max;
|
|
/* 设置当前限制 */
|
if (setrlimit(RLIMIT_NOFILE, &limit) == -1) {
|
perror("setrlimit");
|
exit(EXIT_FAILURE);
|
}
|
|
printf("Max. fd set to %ld successfully!\n", limit.rlim_cur);
|
|
return 0;
|
}
|