LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 02-07-2013, 11:45 PM   #1
antriksh
Member
 
Registered: Aug 2010
Location: In my world
Distribution: RHEL 6.3
Posts: 49

Rep: Reputation: 0
Question What if we run out of pid's?


Hi..This is a hypothetical question. As we know that we can create a limited number of pids.

Code:
cat /proc/sys/kernel/pid_max
That gives 32768 in my system. So that means we can create a max of 32768 in my system. My question is what will happen if suppose all the pids have been used and a new process is forked? So will it replace any existing process?
 
Old 02-08-2013, 12:36 AM   #2
Kaustubh5@ymail.com
LQ Newbie
 
Registered: Jan 2013
Location: India
Distribution: RedHat,Fedora
Posts: 11

Rep: Reputation: Disabled
Hi,

1. Your system will be dead by that time!
2. Yes it will use the PID which were killed/terminated/stopped gracefully.

With general high level server usage, i haven never seen this happening.

Unless you fork to infinite.

-Kaustubh
 
Old 02-08-2013, 12:57 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,778
Blog Entries: 4

Rep: Reputation: 282Reputation: 282Reputation: 282
Lots of documentation is available on this topic. PIDs are recycled and whenever a process gets terminated, it's PID get assigned to other one if waiting.
Concept of paging also comes into the picture, when talking about PIDs allocation.

Check:
1. Process creation in UNIX
2. Process identifier
3. How are PID's generated?
 
Old 02-08-2013, 01:18 AM   #4
antriksh
Member
 
Registered: Aug 2010
Location: In my world
Distribution: RHEL 6.3
Posts: 49

Original Poster
Rep: Reputation: 0
No..I know that PID's get recycled and unused PID will be used. But my question is as i said this is a hypothetical question how the kernel is designed to handle this situation?
We know similar scenario where system runs out of memory and then OOM killer was invoked by kernel and it kills some specific processes based on some algo but do we have any such thing for PID's out of stock?
 
Old 02-08-2013, 08:21 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 1,720

Rep: Reputation: 429Reputation: 429Reputation: 429Reputation: 429Reputation: 429
If you have 32768 active pids in any Intel or ARM based system, it is hung.

But you CAN change it:
Code:
# cd /proc/sys/kernel
# cat pid_max
32768
# echo 50000 >pid_max
# cat pid_max
50000
Which leads me to believe that the /etc/sysctl.conf file can be used to set the value at boot time.

Should have included a reference: http://stackoverflow.com/questions/6...m-pid-in-linux

There it indicates the maximum value is that of the size of pid_t type (from an include file) has 2147483647 for a maximum (I think this is the int arch limit), as pid_t is defined to be an int.

There ARE a few places being more restrictive: /usr/include/asm/posix_types_32.h defines it as a short (the 32768 maximum) for __kernel_ipc_pid_t... so some problems may exist for those processes using shared memory on 32 bit Linux kernels. For all 64 bit, it uses an int (though I don't know why it isn't an unsigned int). The generic case all use "int" for the base (the 2147483647 value)

Last edited by jpollard; 02-08-2013 at 08:40 AM.
 
1 members found this post helpful.
Old 02-09-2013, 01:07 AM   #6
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 3,293

Rep: Reputation: 803Reputation: 803Reputation: 803Reputation: 803Reputation: 803Reputation: 803Reputation: 803
The situation of running out of pid's can be triggered by a fork bomb. This is a good article that also discusses prevention by the use of ulimit.
http://en.wikipedia.org/wiki/Fork_bomb
 
1 members found this post helpful.
Old 02-09-2013, 01:17 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 1,720

Rep: Reputation: 429Reputation: 429Reputation: 429Reputation: 429Reputation: 429
Good fork bombs are hard to kill (they ignore SIGHUP, and all the other signals - execpt SIGKILL (signal 9).

But there are ways... The most reliable is to:

1) increase your priority ("renice -5 $$" where $$ is the shell variable that identifies the running shell itself). This gives the administrator priority over the fork bomb when it comes to running.
2) reduce the priority of all processes owned by the user that started the bomb. This will take several passes of "renice 20 -u <user>" to accomplish that. Then you can do a killall -u <user>.

The best way to prevent them is to impose reasonable limits on the user logins (set their logins ulimits to 5000; this is more than enough for nearly any normal server, though if you have more than 5000 CPUs then up the limit some if they are doing large MPI jobs).
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
(20014)Internal error: Error retrieving pid file /var/run/apache2.pid yuri16 Linux - Server 0 07-28-2009 03:11 AM
(bind) named: couldn't open pid file '/var/run/named/named.pid' - any help? samengr Linux - Server 6 04-01-2009 06:22 AM
/var/run/[XXX].pid - Tcl pid code liguorir Linux - Software 1 05-20-2004 10:32 PM
rm cannot remove /var/run/atd.pid and /var/run/xdm.pid danishmr Linux - Software 1 05-04-2004 08:01 AM
cannot write PID to var/run/news cruella Linux - Newbie 1 01-22-2002 06:51 AM


All times are GMT -5. The time now is 03:13 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration