用于取得 *nix 平台上的 RLIMITs 值,我猜应该是完整列表吧。参考了 apue2e。
#if defined(SOLARIS)
#define _XOPEN_SOURCE 500 /* Single UNIX Specification, Version 2 for Solaris 9 */
#define CMSG_LEN(x) _CMSG_DATA_ALIGN(sizeof(struct cmsghdr)+(x))
#elif !defined(BSD)
#define _XOPEN_SOURCE 600 /* Single UNIX Specification, Version 3 */
#endif
#include <sys/types.h> /* some systems still require this */
#include <sys/stat.h>
#include <sys/termios.h> /* for winsize */
#ifndef TIOCGWINSZ
#include <sys/ioctl.h>
#endif
#include <stdio.h> /* for convenience */
#include <stdlib.h> /* for convenience */
#include <stddef.h> /* for offsetof */
#include <string.h> /* for convenience */
#include <unistd.h> /* for convenience */
#include <errno.h> /* for definition of errno */
#include <stdarg.h> /* ISO C variable aruments */
#include <sys/resource.h>
#define MAXLINE 4096 /* max line length */
#if defined(BSD) || defined(MACOS)
#include <sys/time.h>
#define FMT "%10lld "
#else
#define FMT "%10ld "
#endif /* define(BSD) || defined(MACOS) */
#define doit(name) pr_limits(#name, name)
static void pr_limits(char*, int);
static void err_doit(int, int, const char *, va_list);
static void err_sys(const char *, ...);
int main(void)
{
#ifdef RLIMIT_AS
doit(RLIMIT_AS);
#endif
doit(RLIMIT_CORE);
doit(RLIMIT_CPU);
doit(RLIMIT_DATA);
doit(RLIMIT_FSIZE);
#ifdef RLIMIT_LOCKS
doit(RLIMIT_LOCKS);
#endif
#ifdef RLIMIT_MEMLOCK
doit(RLIMIT_MEMLOCK);
#endif
doit(RLIMIT_NOFILE);
#ifdef RLIMIT_NPROC
doit(RLIMIT_NPROC);
#endif
#ifdef RLIMIT_RSS
doit(RLIMIT_RSS);
#endif
#ifdef RLIMIT_SBSIZE
doit(RLIMIT_SBSIZE);
#endif
doit(RLIMIT_STACK);
#ifdef RLIMIT_VMEM
doit(RLIMIT_VMEM);
#endif
#ifdef RLIMIT_SIGPENDING
doit(RLIMIT_SIGPENDING);
#endif
#ifdef RLIMIT_MSGQUEUE
doit(RLIMIT_MSGQUEUE);
#endif
#ifdef RLIMIT_NICE
doit(RLIMIT_NICE);
#endif
#ifdef RLIMIT_RTPRIO
doit(RLIMIT_RTPRIO);
#endif
#ifdef RLIMIT_TCACHE
doit(RLIMIT_TCACHE);
#endif
#ifdef RLIMIT_AIO_OPS
doit(RLIMIT_AIO_OPS);
#endif
#ifdef RLIMIT_AIO_MEM
doit(RLIMIT_AIO_MEM);
#endif
#ifdef RLIMIT_RSESTACK
doit(RLIMIT_RSESTACK);
#endif
return 0;
}
static void pr_limits(char* name, int resource)
{
struct rlimit limit;
if (getrlimit(resource, &limit) < 0)
err_sys("getrlimit error for %s", name);
printf("%-20s\t", name);
if (limit.rlim_cur == RLIM_INFINITY)
printf("(infinite)\t");
else
printf(FMT, limit.rlim_cur);
if (limit.rlim_max == RLIM_INFINITY)
printf("(infinite)");
else
printf(FMT, limit.rlim_max);
putchar((int)'\n');
}
static void err_sys(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
err_doit(1, errno, fmt, ap);
va_end(ap);
exit(1);
}
static void err_doit(int errnoflag, int error, const char *fmt, va_list ap)
{
char buf[MAXLINE];
vsnprintf(buf, MAXLINE, fmt, ap);
if (errnoflag)
snprintf(buf+strlen(buf), MAXLINE-strlen(buf), ": %s",
strerror(error));
strcat(buf, "\n");
fflush(stdout); /* in case stdout and stderr are the same */
fputs(buf, stderr);
fflush(NULL); /* flushes all stdio output streams */
}
Resource must be one of:
CPU time limit in seconds. When the process reaches the soft limit, it is sent a SIGXCPU signal. The default action for this signal is to terminate the process. However, the signal can be caught, and the handler can return control to the main program. If the process continues to consume CPU time, it will be sent SIGXCPU once per second until the hard limit is reached, at which time it is sent SIGKILL. (This latter point describes Linux 2.2 and 2.4 behaviour. Implementations vary in how they treat processes which continue to consume CPU time after reaching the soft limit. Portable applications that need to catch this signal should perform an orderly termination upon first receipt of SIGXCPU.)
The maximum size of the process's data segment (initialized data, uninitialized data, and heap). This limit affects calls to brk() and sbrk(), which fail with the error ENOMEM upon encountering the soft limit of this resource.
The maximum size of files that the process may create. Attempts to extend a file beyond this limit result in delivery of a SIGXFSZ signal. By default, this signal terminates a process, but a process can catch this signal instead, in which case the relevant system call (e.g., write(), truncate()) fails with the error EFBIG.
A limit on the combined number of flock() locks and fcntl() leases that this process may establish (Linux 2.4 and later).
The maximum number of bytes of virtual memory that may be locked into RAM using mlock() and mlockall().
Specifies a value one greater than the maximum file descriptor number that can be opened by this process. Attempts (open(), pipe(), dup(), etc.) to exceed this limit yield the error EMFILE.
The maximum number of processes that can be created for the real user ID of the calling process. Upon encountering this limit, fork() fails with the error EAGAIN.
Specifies the limit (in pages) of the process's resident set (the number of virtual pages resident in RAM). This limit only has effect in Linux 2.4 onwatrds, and there only affects calls to madvise() specifying MADVISE_WILLNEED.
The maximum size of the process stack, in bytes. Upon reaching this limit, a SIGSEGV signal is generated. To handle this signal, a process must employ an alternate signal stack (sigaltstack(2)).
- RLIMIT_OFILE is the BSD name for RLIMIT_NOFILE.
/*
* AIX 5.3 resource limits
* /usr/include/sys/resource.h
*/
#define RLIMIT_CPU 0 /* cpu time in milliseconds */
#define RLIMIT_FSIZE 1 /* maximum file size */
#define RLIMIT_DATA 2 /* data size */
#define RLIMIT_STACK 3 /* stack size */
#define RLIMIT_CORE 4 /* core file size */
#define RLIMIT_RSS 5 /* resident set size */
#define RLIMIT_AS 6 /* max size proc's total memory--not enforced */
#define RLIMIT_NOFILE 7 /* max # allocated fds--not enforced */
/*
* SunOS 5.10 resource limits
* /usr/include/sys/resource.h
*/
#define RLIMIT_CPU 0 /* cpu time in seconds */
#define RLIMIT_FSIZE 1 /* maximum file size */
#define RLIMIT_DATA 2 /* data size */
#define RLIMIT_STACK 3 /* stack size */
#define RLIMIT_CORE 4 /* core file size */
#define RLIMIT_NOFILE 5 /* file descriptors */
#define RLIMIT_VMEM 6 /* maximum mapped memory */
#define RLIMIT_AS RLIMIT_VMEM
#define RLIM_NLIMITS 7 /* number of resource limits */
#if defined(_LP64)
typedef unsigned long rlim_t;
#define RLIM_INFINITY (-3l)
#define RLIM_SAVED_MAX (-2l)
#define RLIM_SAVED_CUR (-1l)
#else /* _LP64 */
/*
* The definitions of the following types and constants differ between the
* regular and large file compilation environments.
*/
#if _FILE_OFFSET_BITS == 32
typedef unsigned long rlim_t;
#define RLIM_INFINITY 0x7fffffff
#define RLIM_SAVED_MAX 0x7ffffffe
#define RLIM_SAVED_CUR 0x7ffffffd
#else /* _FILE_OFFSET_BITS == 32 */
typedef u_longlong_t rlim_t;
#define RLIM_INFINITY ((rlim_t)-3)
#define RLIM_SAVED_MAX ((rlim_t)-2)
#define RLIM_SAVED_CUR ((rlim_t)-1)
#endif /* _FILE_OFFSET_BITS == 32 */
#endif /* _LP64 */
/*
* linux 2.6 (ubuntu 8.10)
* /usr/include/bits/resource.h
*/
/* Kinds of resource limit. */
enum __rlimit_resource
{
/* Per-process CPU limit, in seconds. */
RLIMIT_CPU = 0,
#define RLIMIT_CPU RLIMIT_CPU
/* Largest file that can be created, in bytes. */
RLIMIT_FSIZE = 1,
#define RLIMIT_FSIZE RLIMIT_FSIZE
/* Maximum size of data segment, in bytes. */
RLIMIT_DATA = 2,
#define RLIMIT_DATA RLIMIT_DATA
/* Maximum size of stack segment, in bytes. */
RLIMIT_STACK = 3,
#define RLIMIT_STACK RLIMIT_STACK
/* Largest core file that can be created, in bytes. */
RLIMIT_CORE = 4,
#define RLIMIT_CORE RLIMIT_CORE
/* Largest resident set size, in bytes.
This affects swapping; processes that are exceeding their
resident set size will be more likely to have physical memory
taken from them. */
__RLIMIT_RSS = 5,
#define RLIMIT_RSS __RLIMIT_RSS
/* Number of open files. */
RLIMIT_NOFILE = 7,
__RLIMIT_OFILE = RLIMIT_NOFILE, /* BSD name for same. */
#define RLIMIT_NOFILE RLIMIT_NOFILE
#define RLIMIT_OFILE __RLIMIT_OFILE
/* Address space limit. */
RLIMIT_AS = 9,
#define RLIMIT_AS RLIMIT_AS
/* Number of processes. */
__RLIMIT_NPROC = 6,
#define RLIMIT_NPROC __RLIMIT_NPROC
/* Locked-in-memory address space. */
__RLIMIT_MEMLOCK = 8,
#define RLIMIT_MEMLOCK __RLIMIT_MEMLOCK
/* Maximum number of file locks. */
__RLIMIT_LOCKS = 10,
#define RLIMIT_LOCKS __RLIMIT_LOCKS
/* Maximum number of pending signals. */
__RLIMIT_SIGPENDING = 11,
#define RLIMIT_SIGPENDING __RLIMIT_SIGPENDING
/* Maximum bytes in POSIX message queues. */
__RLIMIT_MSGQUEUE = 12,
#define RLIMIT_MSGQUEUE __RLIMIT_MSGQUEUE
/* Maximum nice priority allowed to raise to.
Nice levels 19 .. -20 correspond to 0 .. 39
values of this resource limit. */
__RLIMIT_NICE = 13,
#define RLIMIT_NICE __RLIMIT_NICE
/* Maximum realtime priority allowed for non-priviledged
processes. */
__RLIMIT_RTPRIO = 14,
#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
__RLIMIT_NLIMITS = 15,
__RLIM_NLIMITS = __RLIMIT_NLIMITS
#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
#define RLIM_NLIMITS __RLIM_NLIMITS
};
/* Value to indicate that there is no limit. */
#ifndef __USE_FILE_OFFSET64
# define RLIM_INFINITY ((unsigned long int)(~0UL))
#else
# define RLIM_INFINITY 0xffffffffffffffffuLL
#endif
#ifdef __USE_LARGEFILE64
# define RLIM64_INFINITY 0xffffffffffffffffuLL
#endif
作者:lzy.je
出处:http://lzy.iteye.com
本文版权归作者所有,只允许以摘要和完整全文两种形式转载,不允许对文字进行裁剪。未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
// 2009.04.29 添加 ////
/*
* HP-UX 11.23I Resource limits
* /usr/include/sys/resource.h
*/
#if defined(_LARGEFILE64_SOURCE)
# if defined(__L64_MODE__)
# define RLIM64_INFINITY (uint64_t) 0x7fffffffffffffffL
# else /* __L64_MODE__ */
# if defined(__LL_MODE__)
# define RLIM64_INFINITY (uint64_t) 0x7fffffffffffffffLL
# endif /* __LL_MODE__ */
# endif /* __L64_MODE__ */
# define RLIM32_INFINITY (uint32_t) 0x7fffffff
#endif /* _LARGEFILE64_SOURCE */
#if defined(_KERNEL)
# define RLIM_INFINITY RLIM64_INFINITY
# define K_RLIM_INFINITY RLIM_INFINITY
# define ATT_BYTESPERBLOCK 512
# define LOG_ATT_BYTESPERBLOCK 9
/* bytes to 1/2k blocks and 1/2k blocks to bytes conversion macro. */
# define bt2bk(x) (((unsigned long) (x)) >> (LOG_ATT_BYTESPERBLOCK))
# define bk2bt(x) (((unsigned long) (x)) << (LOG_ATT_BYTESPERBLOCK))
# define ULIMIT_MAX bt2bk(0x7fffffff)
# if defined(__L64_MODE__)
# define ULIMIT64_MAX bt2bk(0x7fffffffffffffffL)
# endif /* __L64_MODE__ */
# define ULIMIT32_MAX bt2bk(0x7fffffff)
#else
#if defined(__STDC__)
# if defined(__L64_MODE__)
# define RLIM_INFINITY 0x7fffffffffffffffUL
# else /* __L64_MODE__ */
# if defined(__64BIT_OFF_T)
# if defined(__LL_MODE__)
# define RLIM_INFINITY 0x7fffffffffffffffULL
# endif /* __LL_MODE__ */
# else /* __64BIT_OFF_T */
# define RLIM_INFINITY 0x7fffffffUL
# endif /* __64BIT_OFF_T */
# endif /* __L64_MODE__ */
#else
# if defined(__L64_MODE__)
# define RLIM_INFINITY (uint64_t) 0x7fffffffffffffffL
# else /* __L64_MODE__ */
# if defined(__64BIT_OFF_T)
# if defined(__LL_MODE__)
# define RLIM_INFINITY (uint64_t) 0x7fffffffffffffffLL
# endif /* __LL_MODE__ */
# else /* __64BIT_OFF_T */
# define RLIM_INFINITY (uint32_t) 0x7fffffff
# endif /* __64BIT_OFF_T */
# endif /* __L64_MODE__ */
#endif /* __STDC__ */
#endif /* _KERNEL */
#define RLIMIT_CPU 0 /* cpu time in milliseconds */
#define RLIMIT_DATA 2 /* data size */
#define RLIMIT_STACK 3 /* stack size */
#define RLIMIT_RSS 5 /* resident set size */
#define RLIMIT_FSIZE 1 /* maximum file size */
#define RLIMIT_CORE 4 /* core file size */
#define RLIMIT_NOFILE 6 /* maximum number of open files */
#define RLIMIT_OPEN_MAX RLIMIT_NOFILE /* maximum number of open files */
#define RLIMIT_AS 7 /* maximum number of open files */
#define RLIMIT_TCACHE 8 /* maximum number of cached threads */
#define RLIMIT_AIO_OPS 9 /* maximum number of POSIX AIO ops */
#define RLIMIT_AIO_MEM 10 /* maximum bytes locked for POSIX AIO */
#define RLIMIT_RSESTACK 11 /* RSE stack size */
#define RLIM_NLIMITS 12 /* number of resource limits */
#endif /* _INCLUDE_XOPEN_SOURCE_EXTENDED */
#endif /* _SYS_RESOURCE_INCLUDED */
这几个 limit 不明白意思:
RLIMIT_TCACHE 8 /* maximum number of cached threads */
RLIMIT_AIO_OPS 9 /* maximum number of POSIX AIO ops */
RLIMIT_AIO_MEM 10 /* maximum bytes locked for POSIX AIO */
RLIMIT_RSESTACK 11 /* RSE stack size */
RLIM_NLIMITS 12 /* number of resource limits */
分享到:
相关推荐
Nginx 配置文件主要分成四部分... worker_rlimit_nofile # 指定所有 worker 进程能够打开的最大文件数 worker_cpu_affinity 设置 worker 进程的 CPU 粘性,以避免进程在 CPU 间切换带来的性能消耗。如 worker_cp
Set open file descriptor rlimit#rlimit设置打开的文件描述符 ; Default Value: system defined value rlimit_files = 65535 如果两个值不一样,则要设置为一样 方法如下: 3)设置系统打开文件连接数 [root@...
现在在linux 2.6内核下开启文件打开数为65535,worker_rlimit_nofile就相应应该填写65535。 这是因为nginx调度时分配请求到进程并不是那么的均衡,所以假如填写10240,总并发量达到3-4万时就有进程可能超过...
关于linux下rlimit的介绍以及相关函数
Nginx初认识,总结了user,worker_process,worker_rlimit_nofile,event,http等相关的配置节点。
#运行用户 #user nobody; #启动进程,通常设置成和cpu的...worker_rlimit_nofile 100000; #全局错误日志及PID文件 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;
rlimit, (setf rlimit) 函数rlimit资源 -> 当前,最大值 函数(setf rlimit)资源大小 -> 大小或错误 大小应该是一个整数。 资源应该是以下之一: +RLIMIT-ADDRESS-SPACE+或+RLIMIT-AS+ +RLIMIT-CORE+ +RLIMIT-CPU...
2、节点有user、worker_processes、error_log、pid、worker_rlimit_nofile、worker_connections、multi_accept、use、include、default_type、client_header_buffer_size、upstream、proxy_pass、proxy_set_header等...
Nginx是一款轻量级的高性能的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行...#现在在linux 2.6内核下开启文件打开数为65535,worker_rlimit_nofile就相应应该填写65535。
Nginx限制访问模块一个基于Nginx访问模块的模块,用于使用远程主机的主机名来限制对服务器/...worker_rlimit_core 500M;working_directory /tmp;debug_points abort;events { worker_connections 1024; #use kqueue;
很多情况下,需要使用多个域名,但你只有一台服务器,那如何搭建,让一台服务器可以访问对个域名,下面的方法是在服务器上...worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http {
nginx指令中的优化(配置文件) 代码如下:worker_processes 8; nginx进程数,建议按照cpu数目来... 代码如下:worker_rlimit_nofile 102400; 这个指令是指当一个nginx进程打开的最多文件描述符数目,理论值应该是
当前大并发的网站基本都采用了Nginx来做代理服务器,并且做缓存,来扛住大并发。先前也用nginx配置过简单的代理,今天有时间把整合过程拿出来和大家分享,不过其中大...worker_rlimit_nofile 65535 events { use ep
代码如下: user nfsnobody nfsnobody; #使用的用户和组 worker_processes 8; #指定工作衍生进程数 error_log /usr... #进行PID存放的路劲 worker_rlimit_nofile 65535; #最大文件描述符 events { use epoll;
worker_rlimit_nofile 100000; user和pid应该按默认设置 – 我们不会更改这些内容,因为更改与否没有什么不同。 worker_processes 定义了nginx对外提供web服务时的worker进程数。最优值取决于许多因素,包括(但...
一:500错误 1、500 Internal Server Error 内部... b、如果是too many open files,修改nginx的worker_rlimit_nofile参数,使用ulimit查看系统打开文件限制,修改/etc/security/limits.conf,还是出现too many open
参考popen, pclose源码进行了修改 第一次的问题已解决 如下图 #include #include #include #include #include #include #include ... struct rlimit limit;... if(getrlimit(RLIMIT_NOFILE,&limit) == -1
设置适当的资源限制 ( RLIMIT_MEMLOCK ) 如果ulimit -l沿64K线返回内容,则应进行调整。 在 (例如Ubuntu)中将memlock设置为unlimited,在(例如Clear Linux*)中设置DefaultLimitMEMLOCK=infinity ,或者为你的...
getrlimit(RLIMIT_NOFILE,&l); l.rlim_cur = get_max_connections() + 100; setrlimit(RLIMIT_NOFILE, &l); srs_info("setrlimit => soft:%d , hard:%d\n",(int)l.rlim_cur,(int)l.rlim_max);
#rlimit 包 rlimit 包含有助于复杂速率限制场景的实用程序。 RateLimiter 结构通过使用以固定速率滴答的股票代码和等待重置之前允许的滴答数的指定限制的组合来工作。 这是因为我的应用程序使用的 API 允许以 50 次...