The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
the given code goes in infinite loop and does not increment variable i mrityunjay22 Shell Programming and Scripting 6 12-25-2007 10:20 PM
Infinite Loop in Autosys while running a shell script, Manual run is fine sharmagaurav_2k Shell Programming and Scripting 2 09-04-2007 05:20 AM
pick the bug the server enters an infinite loop arjunjag High Level Programming 3 07-18-2007 10:53 PM
ls command in infinite Loop umakant SUN Solaris 3 07-16-2007 10:25 PM
high priority thread contains an infinite loop rvan High Level Programming 0 02-14-2007 05:30 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-20-2008
Registered User
 

Join Date: Oct 2007
Posts: 19
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Question handling Infinite fork

how Unix handles as process which forks infinitely.
like .......

while(1)
fork();

........
What happens when it is executed and how to avoid it.

Thanks,
Ashish
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-20-2008
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,206
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
It creates as many processes as possible. Many versions of unix are configured with a kernel variable called maxuproc or something like that. It is max processes that a non-root user can create. That is really the only protection and even with that a program like this is a nuisance. As fast as you kill a process, another takes its place.

To recover, as root, su to the user who is running the "while(1) fork();". root will be allowed to switch a root process to this user even if this bumps the number of processes past maxuproc. Now you have a shell running as the user. The shell cannot fork(), but it can exec(). So enter the command:
exec /usr/bin/kill -9 -1
Killing process -1 actually signals all processes owned by the user. This is documented on the kill(2) man page and this is required by posix. If there are a lot of processes and system calls are preemptable and processes with real-time priority are running, this may not work. A second approach is:
exec /usr/bin/kill -STOP -1
The STOP signal, whose number varies from system to system, cannot be caught. It is used for job control and suspends the process. A suspended process cannot attempt to fork() but it continues to consume a process slot so no new process can take its place. Once all of the offending processes are suspended, then you can kill them off.

Shells often have a built-in kill command... if it can handle -1 are a process number, then you can use that. But shells often have built-in kills that choke on the KILLALL constant.
Reply With Quote
  #3 (permalink)  
Old 05-20-2008
Registered User
 

Join Date: Oct 2007
Posts: 19
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by Perderabo View Post
It creates as many processes as possible. Many versions of unix are configured with a kernel variable called maxuproc or something like that. It is max processes that a non-root user can create. That is really the only protection and even with that a program like this is a nuisance. As fast as you kill a process, another takes its place.

To recover, as root, su to the user who is running the "while(1) fork();". root will be allowed to switch a root process to this user even if this bumps the number of processes past maxuproc. Now you have a shell running as the user. The shell cannot fork(), but it can exec(). So enter the command:
exec /usr/bin/kill -9 -1
Killing process -1 actually signals all processes owned by the user. This is documented on the kill(2) man page and this is required by posix. If there are a lot of processes and system calls are preemptable and processes with real-time priority are running, this may not work. A second approach is:
exec /usr/bin/kill -STOP -1
The STOP signal, whose number varies from system to system, cannot be caught. It is used for job control and suspends the process. A suspended process cannot attempt to fork() but it continues to consume a process slot so no new process can take its place. Once all of the offending processes are suspended, then you can kill them off.

Shells often have a built-in kill command... if it can handle -1 are a process number, then you can use that. But shells often have built-in kills that choke on the KILLALL constant.
thanks a lot.
Reply With Quote
  #4 (permalink)  
Old 05-20-2008
Registered User
 

Join Date: Mar 2006
Location: Ahmedabad
Posts: 108
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Further you can impose individual/group specific limit using pam_limit and configurations written in /etc/security/limits.conf file.
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 04:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102