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

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. - ## migrated from stackoverflow.comMar 2 '13 at 6:34 This question came from our site for professional and enthusiast programmers. ## 5 Answers 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  - i tried this sudo ulimit -u 1000 and it again says fork not avaiable. do i need to execute that as root – user1146320 Mar 2 '13 at 2:24 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 Mar 2 '13 at 2:28 my that file is empty , all lines are comments only – user1146320 Mar 2 '13 at 2:33 Yes, then add a newline in that file for the user with the values you're interested. – Tuxdude Mar 2 '13 at 2:34 i tried that and its not working , do i need to restart somethingto makethatwork – user1146320 Mar 2 '13 at 4:46 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. - my that file is empty , is there any other system who can limit the process – user1146320 Mar 2 '13 at 2:32 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.

-
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. –  vonbrand Mar 2 '13 at 11:21
@vonbrand - absolutely. You should post this as the answer with possible things to check. +1 –  jim mcnamara Mar 2 '13 at 11:36
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 –  user825904 Mar 2 '13 at 11:43

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.

-
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 Mar 2 '13 at 16:00
@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 Mar 2 '13 at 16:04
Then Fedora is setup a lot leaner than Ubuntu (my system) by default, or you have trimmed your environment before. –  Olaf Dietsche Mar 2 '13 at 16:13
@OlafDietsche, no trimming here. –  vonbrand Mar 2 '13 at 16:20

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.

-