这里我以MySQL服务为例
$ ps auxf | grep -v grep | grep mysqld
mysql 1204 1.3 3.4 7311604 1134388 ? Sl Aug31 68:40 ./bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --user=mysql --log-error-verbosity=3
$ cat /proc/1204/limits | grep file # 看到文件句柄限制为10240了
Max file size unlimited unlimited bytes
Max core file size 0 unlimited bytes
Max open files 10240 10240 files
Max file locks unlimited unlimited locks
# 用prlimit 搞一下
$ prlimit --nofile=65535:65535 --pid 1204
$ cat /proc/1204/limits | grep file # 再次查看,可以看到已经变成 65535了
Max file size unlimited unlimited bytes
Max core file size 0 unlimited bytes
Max open files 65535 65535 files
Max file locks unlimited unlimited locks
prlimit 还支持其它的参数修改,具体如下
$ prlimit --help
Usage:
prlimit [options] [-p PID]
prlimit [options] COMMAND
General Options:
-p, --pid <pid> process id
-o, --output <list> define which output columns to use
--noheadings don't print headings
--raw use the raw output format
--verbose verbose output
-h, --help display this help and exit
-V, --version output version information and exit
Resources Options:
-c, --core maximum size of core files created
-d, --data maximum size of a process's data segment
-e, --nice maximum nice priority allowed to raise
-f, --fsize maximum size of files written by the process
-i, --sigpending maximum number of pending signals
-l, --memlock maximum size a process may lock into memory
-m, --rss maximum resident set size
-n, --nofile maximum number of open files # 最常用
-q, --msgqueue maximum bytes in POSIX message queues
-r, --rtprio maximum real-time scheduling priority
-s, --stack maximum stack size
-t, --cpu maximum amount of CPU time in seconds
-u, --nproc maximum number of user processes # 常用
-v, --as size of virtual memory
-x, --locks maximum number of file locks
-y, --rttime CPU time in microseconds a process scheduled
under real-time scheduling
Available columns (for --output):
DESCRIPTION resource description
RESOURCE resource name
SOFT soft limit
HARD hard limit (ceiling)
UNITS units
For more details see prlimit(1).