Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux PID recycling [closed]

Tags:

linux

pid

recycle

Is there any policy in Linux as to the recycling of used PIDs ? I mean, if a PId has been used, how much later will it be used again ?

like image 527
Cygnus Avatar asked Jul 04 '12 06:07

Cygnus


People also ask

Do PIDs get reused?

As long as a process is dead and has been waited for (by its parent, or the sub child reaper or init if the parent is dead), its pid can be reused. Those are approximations as the shell (most shells) language doesn't give you any better API to handle child processes.

Can process id be the same?

Since PID is an unique identifier for a process, there's no way to have two distinct process with the same PID. Unless the processes are running in a separate PID namespaces (and thus can have the same PID).

Are PIDs unique?

Most PIDs have a unique identifier which is linked to the current address of the metadata or content. Unlike URLs, PIDs are often provided by services that allow you to update the location of the object so that the identifierconsistently points to the right place without breaking.

Can PID change Linux?

PID in Linux and Windows are unique to that process. PIDs will never change.


2 Answers

As new processes fork in, PIDs will increase to a system-dependent limit and then wrap around. The kernel will not reuse a PID before this wrap-around happens.

The limit (maximum number of pids) is /proc/sys/kernel/pid_max. The manual says:

/proc/sys/kernel/pid_max (since Linux 2.5.34)

This file specifies the value at which PIDs wrap around (i.e., the value in this file is one greater than the maximum PID). The default value for this file, 32768, results in the same range of PIDs as on earlier kernels

like image 198
cnicutar Avatar answered Oct 14 '22 15:10

cnicutar


https://superuser.com/questions/135007/how-are-pids-generated

This should answer your question - it appears it will recycle PIDs when it runs out, skipping the ones that are still assigned.

like image 22
Osmium USA Avatar answered Oct 14 '22 15:10

Osmium USA