how to change the maximum number of fork process by user in linux

7

1

Whenever I login to shell, I get this error

-bash: fork: Resource temporarily unavailable
-bash-3.2$

I can't seem to execute any command which uses fork().

I tried ulimit -u as it doesn't use fork and it returned 35. Somehow my max process is set to 35.

I want to increase that, but I don't know where to make that change.

user1146320

Posted 2013-03-02T02:06:53.537

Reputation: 233

Answers

10

If you would like to change the limit only for that shell, you could run:

sudo ulimit -u 1000

If you want to make a more permanent change, you need to edit either /etc/limits.conf or /etc/security/limits.conf (depending on your linux distro) and add the following lines:

username hard nproc 1000

Substitute username with the actual user name

Instead of username a groupname can also be used if you prefix it with an @. If you use * it would be the default for all users

Examples:

myuser hard nproc 1000
@mygroup hard nproc 3000
*    hard nproc 500

Tuxdude

Posted 2013-03-02T02:06:53.537

Reputation: 609

i tried this sudo ulimit -u 1000 and it again says fork not avaiable. do i need to execute that as root – user1146320 – 2013-03-02T02:24:47.797

Ahh, sudo again requires to fork a process - dang! I guess the only other way is to modify the limits.conf by directly logging in as root. – Tuxdude – 2013-03-02T02:28:54.377

my that file is empty , all lines are comments only – user1146320 – 2013-03-02T02:33:14.747

Yes, then add a newline in that file for the user with the values you're interested. – Tuxdude – 2013-03-02T02:34:33.187

i tried that and its not working , do i need to restart somethingto makethatwork – user1146320 – 2013-03-02T04:46:58.173

The user would at least need to logout completely and login again for the changes to take effect. Yes try restarting the box, if that helps. – Tuxdude – 2013-03-03T06:02:37.497

3

This can be changed in /etc/security/limits.conf. Look for lines of the form:

username hard nproc 25
@groupname hard nproc 100

These lines limit username user to 25 processes and users in group groupname to 100 processes. You will need root permissions on the machine though.

jman

Posted 2013-03-02T02:06:53.537

Reputation: 386

my that file is empty , is there any other system who can limit the process – user1146320 – 2013-03-02T02:32:41.580

0

Here some ideas :

If your limits.conf is empty, grep -l ulimit /etc/* $HOME/.* 2> /dev/null to check if someone has set a ulimit somewhere, and remove it.

After editing limits.conf, all you have to do is to logout and login again to take effect.

To gain a process, use exec. Try for instance exec sudo su to become root.

Edouard Thiel

Posted 2013-03-02T02:06:53.537

Reputation: 101

1It should be enough to (re)set the ulimit, no need to change configuration (let alone system-wide configuration under /etc). And 35 processes should be plenty, something is wrong with the login process of OP. – vonbrand – 2013-03-02T11:21:17.597

@vonbrand - absolutely. You should post this as the answer with possible things to check. +1 – jim mcnamara – 2013-03-02T11:36:32.120

i had two files , /etc/profile and /etc/bashrc this was the line ulimit -n 100 -u 35 -m 200000 -d 200000 -s 8192 -c 200000 -v unlimited 2>/dev/null – Mirage – 2013-03-02T11:43:33.353

0

It should be enough to (re)set the ulimit, no need to change configuration (let alone system-wide configuration under /etc). And 35 processes should be plenty, something is wrong with the login process of OP.

In a terminal run ps -au, that should show all processes running as you, check the list (or post it here) to see if something strange is going on.

vonbrand

Posted 2013-03-02T02:06:53.537

Reputation: 2 083

When I look at my process list, I have over 40 processes, started by the gnome environment alone. Not counting the processes I started, like firefox, emacs, bash, ... So, a ulimit of 35 isn't really that much nowadays, if you use a graphical environment. – Olaf Dietsche – 2013-03-02T16:00:37.557

@OlafDietsche, Fedora 18 Gnome 3 here; I'm running Firefox, 2 xterms (one with 6 tabs) and an assortment of applets. 17 processes in all. – vonbrand – 2013-03-02T16:04:02.413

Then Fedora is setup a lot leaner than Ubuntu (my system) by default, or you have trimmed your environment before. – Olaf Dietsche – 2013-03-02T16:13:04.223

@OlafDietsche, no trimming here. – vonbrand – 2013-03-02T16:20:20.993

0

As others already mentioned look at limits.conf. When you login into Gnome, KDE or any other GUI, you have likely more than 35 processes running already.

Logout from the GUI and switch to a VT with Ctl Alt F1, for example, and login without a GUI.

Now you should be able to look into /etc/security/limits.conf. If it is empty or all commented out, you can look, if there's something in the directory /etc/security/limits.d, which has reduced the ulimit.

On the console, you should also be able to start additional processes for editing or adjusting limits.conf or files in limits.d.

Olaf Dietsche

Posted 2013-03-02T02:06:53.537

Reputation: 421

0

There is one more possibility that the configuration for "noproc" is not working while configuring in /etc/security/limits.conf.

There is one more file which overrides your configuration /etc/security/limits.d/90-nproc.conf.

*          soft    nproc     1024
root       soft    nproc     unlimited

Here * config will override whatever you set in previous config file. So ideally you configure your setting in this file.

Suyash Jain

Posted 2013-03-02T02:06:53.537

Reputation: 236