4

If a program has a process ID of P, will the child processes (and their children) have process IDs which are strictly greater then P?

When process IDs are reused, which process IDs are chosen e.g., is the lowest process ID available?

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
Bilal Syed Hussain
  • 8,664
  • 11
  • 38
  • 44
  • 1
    Does it really matter? – HAL Dec 12 '13 at 10:06
  • 3
    @HAL That doesn't help answer the question – Sash Dec 12 '13 at 10:09
  • Really not a programming question but more a Linux question. – m0skit0 Dec 12 '13 at 10:10
  • 3
    Have a look at this post, this seems to explain it http://superuser.com/questions/135007/how-are-pids-generated – Sash Dec 12 '13 at 10:10
  • @Sash Its not an answer. Just want to know how knowing this will affect your program. – HAL Dec 12 '13 at 10:13
  • I wanted to get all child processes (and the all their children) http://stackoverflow.com/questions/20533979/how-to-get-all-descendent-child-process-id-of-pid-in-c-in-linux/20535264#20535264. The answer seems to be to look though all the processes in /proc. So I was wondering if I can just check the process ids that are greater then the parent pid. – Bilal Syed Hussain Dec 12 '13 at 10:46

2 Answers2

4

From http://en.wikipedia.org/wiki/Process_identifier

Process IDs are usually allocated on a sequential basis, beginning at 0 and rising to a maximum value which varies from system to system. Once this limit is reached, allocation restarts at 300 and again increases. In Mac OS X and HP-UX, allocation restarts at 100. However, for this and subsequent passes any PIDs still assigned to processes are skipped. Some consider this to be a potential security vulnerability in that it allows information about the system to be extracted, or messages to be covertly passed between processes. As such, implementations that are particularly concerned about security may choose a different method of PID assignment.[1] On some systems, like MPE/iX, the lowest available PID is used, sometimes in an effort to minimize the number of process information kernel pages in memory.

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

Community
  • 1
  • 1
Sash
  • 4,448
  • 1
  • 17
  • 31
2

Every new process provide the process id ,and every process has unique process id. That id is non-integer value ,Once the process terminate the process ids are reused That mean the terminate process id again used for another process The maximum process id created by kernel that maximum pid is 32768 That maximum pid stored in /proc/sys/kernel/pid_max that file contain the maximum pid . Once exceed the limit of pid again it will start which process id is unused that is assigned for the process. The process id created by kernel for using fork() system call.

Kalanidhi
  • 4,902
  • 27
  • 42