#include
#include
main()
{
struct rlimit rlimit;
if (getrlimit(RLIMIT_NOFILE, &rlimit) == -1) {
perror("getrlimit fails");
exit(1);
}
printf("File soft limit: %dn", rlimit.rlim_cur);
printf("File hard limit: %dn", rlimit.rlim_max);
}
Here is a sample run of this program:
$ cc getlimit.c -o getlimit
$ ulimit -n
512
$ getlimit
File soft limit: 512
File hard limit: 512
$ ulimit -n 256
$ getlimit
File soft limit: 256
File hard limit: 256
$
The number we are most interested in is the hard limit. This is the limit placed on the process by the environment. The soft limit can be raised or lowered by the process by using setrlimit(2), but the hard limits cannot be exceeded without root permissions. One point to notice in the preceding output is that the shell used for the example (ksh) adjusts both the hard and soft limits; this is the reason for the change of both values. That behavior can be modified with flags.
To summarize, the number of files a user process can open is limited in three ways. The ultimate limit is set by the kernel variable fd_rlim_max. That value is inherited by every user process and cannot be exceeded. The second limit is placed by the shell. The shell will inherit the kernel settings and can adjust the hard and soft values using the ulimit command. As noted earlier, the shell cannot adjust to values above the hard limit. The final limit is placed by the executable itself. The executable can adjust the limits using rlimit() to raise or lower the soft limit, but it cannot exceed the hard limit in the environment.
REFERENCES:
Solaris manpages: open(2), fopen(3C), setrlimit(2), getrlimit(2), Solaris Tunable Parameters Reference Manual
推荐阅读
- Quick_Instaling_OpenSSH_for_Solaris 8.0_method-1
- Solaris OpenBoot PROM
- Solaris 8 定制OpenWindows工作区
- 在本地OpenWindows V3.x系统显示远程操作OpenWindows V2.x
- Solaris 8 如何定制您的OpenWindows工作区
- 如何在本地OpenWindows V3.x系统显示远程OpenWindows V2.x
- 续 HOPEN智能嵌入手机操作系统之艰难摸索
- HOPEN智能嵌入手机操作系统之艰难摸索
- oc是什么意思
- no和nc表示什么
