Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 1
    If you are using C, see also getrusage(2) and times(2). Commented Apr 10, 2016 at 8:34
  • pid values are not re-used. The count will be incremented with each new process. The only 'reasonable' method of resetting the count is to re-boot the computer. Commented Apr 10, 2016 at 18:23
  • 1
    @user3629249 That's completely wrong. PID values are reused. Commented Apr 10, 2016 at 20:39
  • 1
    /proc/<pid>/stat no longer exists by the time wait returns. You mention a short delay during which it still exists, but that doesn't jibe with my reading of the code, nor with my understanding of the architecture (the data is supposed to be reclaimed when the parent calls wait), and I cannot reproduce this on Debian jessie. What kernel version are you using? Are you absolutely sure about the timing and that you're hitting the right child? In any case, it's clearly not something you can count on. Commented Apr 11, 2016 at 0:30
  • 1
    @user3629249 Once again, no. Try it on Linux, for example: if you leave it running for long enough, eventually the PIDs reach 32767, which is the maximum value, and then they start again at the first free PID. If PIDs were never reused, that would mean that the system would lock up after a certain number of forks! How long you have before a PID is reused depends on how long the process survived: if it survived for about 32700 forks, the PID could be the next one to be reused. Commented Apr 12, 2016 at 7:26