Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm doing some simulation work with Linux, and the code I'm working on right now only works under the assumption that, once a process has been assigned a PID by the kernel, that PID will remain the same until the process is killed. I would assume this is true but since I'm kind of new to the Linux world I just want to see if there are any special circumstances I ought to be aware of. Thanks!

share|improve this question
up vote 8 down vote accepted

Yes, it's guaranteed. Process will have the same PID even if its image will be replaced with another one by exec system call.

share|improve this answer
Well, a malicious programmer can break the guarantee, but this is generally true of well behaved programs. – dmckee Aug 5 '12 at 1:08
I can't agree with you, since fork creates new process with same image it's naturally that this new process has another PID value. In case from your answer I would say that program changes its PID (by changing its process), but not the process (and the question is about processes). – xaizek Aug 5 '12 at 8:16
That is, of course, strictly true, but that simply reflects the definition of "process" that the OS uses. The user will see a continuity of state with a changing number, and if she was counting on the presence/absence of the PID to determine if some state was present on the machines this would be a problem. That's why I called the behavior malicious. – dmckee Aug 6 '12 at 17:22


As other posters have said any particular process will retain it's PID indefinitely. Even through one or more instances of exec.

However, a programmer who wished to evade that guarantee on a unix box would have no trouble at all. He would simple fork, ignore HUP signals in the daughter and then kill the mother process. The result of which would be the daughter carrying on with a new PID and give the appearance that the process changed it's PID.

share|improve this answer

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .