linux getrlimit sysconf

linux中getrlimit和sysconf


/***************************************************************
    > File Name: rlimit_sysconf.c
    > Author: lxg
    > Mail: [email protected]
    > Created Time: 2015年06月22日 星期一 10时28分54秒
 ***************************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<errno.h>
#include<sys/time.h>
#include<sys/resource.h>

int main(int argc, char *argv[])
{
    int max_fd = -1;
    struct rlimit rlim;

    if((max_fd = sysconf(_SC_OPEN_MAX)) == -1)
    {
        fprintf(stderr, "sysconf _SC_OPEN_MAX error:%s", strerror(errno));
    }

    if(getrlimit(RLIMIT_NOFILE, &rlim) == -1)
    {
        fprintf(stderr, "getrlimit RLIMIT_NOFILE error:%s\n", strerror(errno));
    }

    printf("sysconf _SC_OPEN_MAX=%d, getrlimit RLIMIT_NOFILE=%lld\n", max_fd, (long long)rlim.rlim_cur);

    return 0;
}

[email protected]:~/station/TLPI/chapter_36$ ulimit -n

2048

系统中RLIMIT_NOFILE的输出

[email protected]:~/station/TLPI/chapter_36$ ./rlimit_sysconf

sysconf _SC_OPEN_MAX=2048, getrlimit RLIMIT_NOFILE=2048

rlimit_sysconf的运行结果

[email protected]:~/station/TLPI/chapter_36ulimit?n1024lxg@lxg?X240: /station/TLPI/chapter36 ulimit -n

1024

修改系统的RLIMIT_NOFILE值为1024

[email protected]:~/station/TLPI/chapter_36$ ./rlimit_sysconf

sysconf _SC_OPEN_MAX=1024, getrlimit RLIMIT_NOFILE=1024

rlimit_sysconf的运行结果

从上面的测试结果来看:getrlimit和sysconf至少在某些参数的结果上来看是功能一致的。

时间: 2024-08-26 09:41:26

linux getrlimit sysconf的相关文章

测试CPU核心个数

//测试CPU核心个数 #if !defined (_WIN32) && !defined (_WIN64) #define LINUX #include <unistd.h> #else #define WINDOWS #include <windows.h> #endif unsigned core_count() { unsigned count = 1; // 至少一个 #if defined (LINUX) count = sysconf(_SC_NPRO

linux下getrlimit与sysconf函数

#include <stdio.h> #include <sys/time.h> #include <sys/resource.h> int main(int argc, char *argv[]) { struct rlimit nofile_rlmt; if (getrlimit(RLIMIT_NOFILE, &nofile_rlmt) != -1) { printf("获取进程最大能打开的文件描写叙述符个数信息:\n" "rl

Linux系统调用--getrlimit()与setrlimit()函数详解

http://www.cnblogs.com/niocai/archive/2012/04/01/2428128.html 功能描述:获取或设定资源使用限制.每种资源都有相关的软硬限制,软限制是内核强加给相应资源的限制值,硬限制是软限制的最大值.非授权调 用进程只可以将其软限制指定为0~硬限制范围中的某个值,同时能不可逆转地降低其硬限制.授权进程可以任意改变其软硬限制.RLIM_INFINITY的 值表示不对资源限制. 用法: #include <sys/resource.h>int getr

Linux的getrlimit与setrlimit系统调用

转自:http://www.cnblogs.com/niocai/archive/2012/04/01/2428128.html 功能描述:获取或设定资源使用限制.每种资源都有相关的软硬限制,软限制是内核强加给相应资源的限制值,硬限制是软限制的最大值.非授权调用进程只可以将其软限制指定为0~硬限制范围中的某个值,同时能不可逆转地降低其硬限制.授权进程可以任意改变其软硬限制.RLIM_INFINITY的值表示不对资源限制. 用法: #include <sys/resource.h> int ge

Linux函数整理 sysconf

sysconf这个函数用来获取系统执行的配置信息.例如页大小.最大页数.cpu个数.打开句柄的最大个数等. #include <stdio.h> #include <unistd.h> #define ONE_MB (1024 * 1024) int main() { //处理器数目 printf("The number of processors configured is :%ld\n", sysconf(_SC_NPROCESSORS_CONF)); pr

Process Kill Technology &amp;&amp; Process Protection Against In Linux

目录 0. 引言 1. Kill Process By Kill Command 2. Kill Process By Resource Limits 3. Kill Process By Code Injection Into Running Process Via GDB 4. Kill Process By Using Cross Process Virtual Memory Modify 5. Kill Process By Using ptrace To Inject .so 6. P

Linux系统开发6 信号

[本文谢绝转载,原文来自http://990487026.blog.51cto.com] <大纲> Linux系统开发6 信号 linux系统有64种信号 signal man文档 终端按键信号 ctrl +c SIGIN ctrl +z SIGTSTP ctrl +\ SIGQUIT 硬件产生信号 浮点数例外信号  访问非法内存 kill()函数 信号与权限 kill()函数的pid 与返回值 信号产生原因 raise() 信号 abort() 信号 alarm() 信号 收到信号的默认操作

Linux 进程(一):环境及其控制

进程环境 main启动 当内核执行C程序时,在调用main前先调用一个特殊的启动例程.可执行程序将此启动例程指定为程序的起始地址,接着启动例程从内核中取出命令行参数和环境变量值,然后执行main函数. 进程终止 使进程终止的方式有8种,其中5种为正常终止,3种为异常终止: 终止类型 说明 正常终止 (1)   从main返回 (2)   调用exit (3)   调用_exit或_Exit (4)   最后一个线程从启动例程返回 (5)   在最后一个线程中调用pthread_exit 异常终止

Linux进程详解

本文实际上是 "UNIX环境高级编程" 的读书笔记. 所以许多细节并没有表述出来, 想要刨根问底的同学建议再看看原书. 之所以把读书笔记贴到博客上, 出于两个目的: 1. 加深自己的学习效果. 2. 提供一个快速浏览的方式. 本文提到的技术在下面的环境中实际验证过: Linux version 2.6.18-164.el5 x86_64 GNU/Linux (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) 程序和进程 程序是指磁盘上的可执行