Error: Cannot fork: Resource temporarily unavailable

By: Published: Feb 12th, 2013 Category: Linux Tips

Recently my friend (a Developer) came to me with a problem he was facing on his testing server which executing a Perl script. I have checked and found that the Perl script was throwing error “Cannot fork: Resource temporarily unavailable” while executing it.

test@server.test.com [~]# /usr/local/bin/perl /home/test/cr/spamcheck.pl
Cannot fork: Resource temporarily unavailable at /usr/lib/perl5/site_perl/5.8.8/Parallel/ForkManager.pm line 290.
test@server.test.com [~]#

 

** In above case I am trying to execute the Perl script under user “test

This problem occurs mainly when you are trying to execute a script with a normal user (or jailshell user but not root) where the Server restricts number of processes should run under a user.

To fix this problem you will have to increase the process limits for the user or you can tell OS to skip the process limits for the user. You will have to edit following files to to ignore the process limits for a particular user.

Open Following files (one by one) in your favorite editor.

  1. /etc/profile
  2. /etc/bashrc
  3. /etc/profile.d/limits.sh

Now search for “if [ "$LIMITUSER" != "root" ]; then” and change it

FROM:

LIMITUSER=$USER
if [ -e "/usr/bin/whoami" ]; then
LIMITUSER=root
fi
if [ "$LIMITUSER" != "root" ]; then
ulimit -n 100 -u 20 -m 200000 -d 200000 -s 8192 -c 200000 -v 200000 2>/dev/null
else
ulimit -n 4096 -u 14335 -m unlimited -d unlimited -s 8192 -c 1000000 -v unlimited 2>/dev/null
fi

 

TO:

if [ -e "/usr/bin/whoami" ]; then
LIMITUSER=`/usr/bin/whoami`
fi
if [ "$LIMITUSER" != "root" ] && [ "$LIMITUSER" != "USERNAME" ]; then
ulimit -n 100 -u 35 -m 200000 -d 200000 -s 8192 -c 200000 -v 200000 2>/dev/null
else
ulimit -n 4096 -u 14335 -m unlimited -d unlimited -s 8192 -c 1000000 -v unlimited 2>/dev/null
fi

 

Here, USERNAME is the name of the user under which you are executing the script. In my case I have set the USERNAME to test.

 Error: Cannot fork: Resource temporarily unavailable

About 

Milind Koyande is a Project Manager and his job is to work with new technologies, specially Cloud Computing / Virtualization Technology. His past projects include Government Sector initiatives, Backup and Disaster Recovery Solutions.

Tags: , , ,

Leave a Reply

Subscribe to eITWebguru

© 2012 eITWebguru. All Rights Reserved.