Fork:resource unavailable

Hello. I have code which create processes with fork(). I set a limit for processes by typing ulimit -u 20. Then I run my code who should create 100 processes. Unfortunately, I have a mistake there and I forgot to quit all of my forked processes when fork gave me return value -1. So I am trapped in bash by fork:resource unavailable and i dont know how to kill all of the processes i created. Could anyone help me please?
Thanks a lot.

If your process is running on foreground Ctrl + C can kill existing process.
Or use ps -ef | grep "Script Name".
then use kill -9 "Process ID".
Or you can use ps -ef | more to find all process IDs and then kill them one by one.

problem is i have run som many processes that i cannot do fork anymore which means i am not able to do ps

I think there are three more ways.

  1. If you can close some other process first like shutting down database or any web service it allows (B/W I think it wont allow any).
  2. Hard reboot the machine. (One fine day I came up with similar situation in AIX it was saying cannot create fork process so I hard rebooted the machine and nuffin else. My system's memory utilization RAM + Paging reached 100%)
  3. Anyone have better idea? :slight_smile:
    Wish you luck.
    Regards

Bash may still be able to exec. this would replace the shell rather than creating a new process.

The exec trick will work only once. If you feed kill a pid of -1 it will kill all of your processes. So do:
exec /usr/bin/kill -9 -1
or
exec /bin/kill -9 -1
depending on where your kill executable resides.