Skip to content

Instantly share code, notes, and snippets.

@sennajox
Last active December 14, 2015 15:28
Show Gist options
  • Save sennajox/5107621 to your computer and use it in GitHub Desktop.
Save sennajox/5107621 to your computer and use it in GitHub Desktop.
A simple script to update the nproc of the specified process
#!/bin/bash
if [ $# -lt 1 ];then
echo "usage:$0 pid [nproc=1024000]"
exit 1
fi
pid=$1
if [ $# -ge 2 ];then
nproc="$2ll"
else
nproc="1024000ll"
fi
# 修改nproc
#Limit Soft Limit Hard Limit Units
#Max cpu time unlimited unlimited seconds
#Max file size unlimited unlimited bytes
#Max data size unlimited unlimited bytes
#Max stack size 10485760 unlimited bytes
#Max core file size unlimited unlimited bytes
#Max resident set unlimited unlimited bytes
#Max processes 1024 unlimited processes
#Max open files 65536 65536 files
#Max locked memory 65536 65536 bytes
#Max address space unlimited unlimited bytes
#Max file locks unlimited unlimited locks
#Max pending signals 256265 256265 signals
#Max msgqueue size 819200 819200 bytes
#Max nice priority 0 0
#Max realtime priority 0 0
#Max realtime timeout unlimited unlimited us
# setrlimit第一个参数为 `cat /proc/pid/limits` 后得到的列表中的偏移(从0开始)
gdb -p $pid << EOF >> nproc.log 2>&1
set \$rlim = &{$nproc, $nproc}
p setrlimit(6, \$rlim)
detach
quit
EOF
# 查看是否修改成功
cat /proc/$pid/limits | grep "Max processes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment