Is a process PID guaranteed to stay the same as long as the process doesn't die?

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


Well...mostly.

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.


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

Tags:

Linux

Process

Pid