Resolution for error: su: failed to execute /bin/bash: Resource temporarily unavailable


Today we met a problem about user cannot su to a general dev account with the error message below:

su: failed to execute /bin/bash: Resource temporarily unavailable

And checked the /var/log/message and /var/log/secure, found there is no resource available for the fork() to generate new processes.

sshd[22208]: error: do_exec_pty: fork: Resource temporarily unavailable

Refer to: http://www.csl.mtu.edu/cs4411.ck/www/NOTES/process/fork/create.html  if you are interested in fork function.

 

Then we checked the max user processes for this user:

[test@hostname ~]$ ulimit -a

core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 127951
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 4096
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

[Test@lvs-genas-008 log]$ cat /proc/sys/fs/file-nr
1536   0   3247300

Or use lsof to check the opening files || processes.

Opened too files. 

Resolution: we just need to increase the open files param.

系統設置--ulimit
語  法:ulimit [-aHS][-c <core文件上 限>][-d <數據節區大小>][-f <文件大小>][-m <內存大小>][-n <文件數 目>][-p <緩沖區大小>][-s <堆疊大小>][-t <CPU時間>][-u <程序數 目>][-v <虛擬內存大小>]

補充說明:ulimit為shell內建指令,可用來控制shell執行程序的資源。

參  數:
  -a  顯示目前資源限制的設定。 
  -c <core文件上限>  設定core文件的最大值,單位為區塊。 
  -d <數據節區大小>  程序數據節區的最大值,單位為KB。 
  -f <文件大小>  shell所能建立的最大文件,單位為區塊。 
  -H  設定資源的硬性限制,也就是管理員所設下的限制。 
  -m <內存大小>  指定可使用內存的上限,單位為KB。 
  -n <文件數目>  指定同一時間最多可開啟的文件數。 
  -p <緩沖區大小>  指定管道緩沖區的大小,單位512字節。 
  -s <堆疊大小>  指定堆疊的上限,單位為KB。 
  -S  設定資源的彈性限制。 
  -t <CPU時間>  指定CPU使用時間的上限,單位為秒。 
  -u <程序數目>  用戶最多可開啟的程序數目。 
  -v <虛擬內存大小>  指定可使用的虛擬內存上限,單位為KB。
 
We can use ulimit -n number  to modify the opening files number.
 
Another way is:

Append a new line to current user's ./bash_profile

ulimit –n 65535

next time when get into this user's shell, will be good, no need to restart server.

Third way is change below file directly:

/etc/security/limits.conf

@test   soft    nofile           65535

@test          hard    nofile           65535

@test          soft    nproc           65535

@test          hard    nproc           65535

 

After a while the file will sync to server, also no need to reboot server.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM