PID reuse possibility in Linux
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
In a Linux operating system, is there any chance that a PID can be reused?
For example, A PID is named 2252. This PID is dead and erased from kernel process table. Is there any chance that the process table can re-use a same PID for a new process, or it will not be used in any of the upcoming processes?
linux linux-kernel process
add a comment |Â
up vote
2
down vote
favorite
In a Linux operating system, is there any chance that a PID can be reused?
For example, A PID is named 2252. This PID is dead and erased from kernel process table. Is there any chance that the process table can re-use a same PID for a new process, or it will not be used in any of the upcoming processes?
linux linux-kernel process
duplicate? stackoverflow.com/questions/18122592/â¦
â Michael D.
Jan 5 at 11:42
No. Not a duplicate. the process is dead and removed from server. But is there any possibility that the same PID kernel can assign to future processes.
â Athiri
Jan 5 at 11:44
I can only guess - ifcat /proc/sys/kernel/pid_max
is reached, it might start from 2 looking for the next available, unused pid. I'd say yes.
â Michael D.
Jan 5 at 11:50
Ok. So in my case PID-2252 will be reused. Thanks Mike.
â Athiri
Jan 5 at 11:58
1
relating: unix.stackexchange.com/q/16883/117549
â Jeff Schaller
Jan 5 at 12:06
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
In a Linux operating system, is there any chance that a PID can be reused?
For example, A PID is named 2252. This PID is dead and erased from kernel process table. Is there any chance that the process table can re-use a same PID for a new process, or it will not be used in any of the upcoming processes?
linux linux-kernel process
In a Linux operating system, is there any chance that a PID can be reused?
For example, A PID is named 2252. This PID is dead and erased from kernel process table. Is there any chance that the process table can re-use a same PID for a new process, or it will not be used in any of the upcoming processes?
linux linux-kernel process
edited Jan 5 at 12:01
Jeff Schaller
31.8k848109
31.8k848109
asked Jan 5 at 11:35
Athiri
258
258
duplicate? stackoverflow.com/questions/18122592/â¦
â Michael D.
Jan 5 at 11:42
No. Not a duplicate. the process is dead and removed from server. But is there any possibility that the same PID kernel can assign to future processes.
â Athiri
Jan 5 at 11:44
I can only guess - ifcat /proc/sys/kernel/pid_max
is reached, it might start from 2 looking for the next available, unused pid. I'd say yes.
â Michael D.
Jan 5 at 11:50
Ok. So in my case PID-2252 will be reused. Thanks Mike.
â Athiri
Jan 5 at 11:58
1
relating: unix.stackexchange.com/q/16883/117549
â Jeff Schaller
Jan 5 at 12:06
add a comment |Â
duplicate? stackoverflow.com/questions/18122592/â¦
â Michael D.
Jan 5 at 11:42
No. Not a duplicate. the process is dead and removed from server. But is there any possibility that the same PID kernel can assign to future processes.
â Athiri
Jan 5 at 11:44
I can only guess - ifcat /proc/sys/kernel/pid_max
is reached, it might start from 2 looking for the next available, unused pid. I'd say yes.
â Michael D.
Jan 5 at 11:50
Ok. So in my case PID-2252 will be reused. Thanks Mike.
â Athiri
Jan 5 at 11:58
1
relating: unix.stackexchange.com/q/16883/117549
â Jeff Schaller
Jan 5 at 12:06
duplicate? stackoverflow.com/questions/18122592/â¦
â Michael D.
Jan 5 at 11:42
duplicate? stackoverflow.com/questions/18122592/â¦
â Michael D.
Jan 5 at 11:42
No. Not a duplicate. the process is dead and removed from server. But is there any possibility that the same PID kernel can assign to future processes.
â Athiri
Jan 5 at 11:44
No. Not a duplicate. the process is dead and removed from server. But is there any possibility that the same PID kernel can assign to future processes.
â Athiri
Jan 5 at 11:44
I can only guess - if
cat /proc/sys/kernel/pid_max
is reached, it might start from 2 looking for the next available, unused pid. I'd say yes.â Michael D.
Jan 5 at 11:50
I can only guess - if
cat /proc/sys/kernel/pid_max
is reached, it might start from 2 looking for the next available, unused pid. I'd say yes.â Michael D.
Jan 5 at 11:50
Ok. So in my case PID-2252 will be reused. Thanks Mike.
â Athiri
Jan 5 at 11:58
Ok. So in my case PID-2252 will be reused. Thanks Mike.
â Athiri
Jan 5 at 11:58
1
1
relating: unix.stackexchange.com/q/16883/117549
â Jeff Schaller
Jan 5 at 12:06
relating: unix.stackexchange.com/q/16883/117549
â Jeff Schaller
Jan 5 at 12:06
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
7
down vote
Of course. Otherwise a system could only run 32768 processes (or whatever the maximum pid number is on the system) per boot.
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.
You see scripts doing things like:
cmd1 & pid1=$!
something else
cmd2 & pid2=$!
more things
kill "$pid1" "$pid2"
Those are approximations as the shell (most shells) language doesn't give you any better API to handle child processes.
There's no guarantee that $pid1
and/or $pid2
will still refer to the processes that were started earlier if those processes may have died. $pid1
and $pid2
could also be the same (if cmd1
has died by the time cmd2
is started). So kill
could kill the wrong processes.
In practice, it's rarely a problem especially on systems where pids are assigned in sequence as it takes quite some time for pid numbers to wrap. But it can become so when the pid table gets full (like when it's filled with zombie processes) and some attackers can get advantage of that.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
Of course. Otherwise a system could only run 32768 processes (or whatever the maximum pid number is on the system) per boot.
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.
You see scripts doing things like:
cmd1 & pid1=$!
something else
cmd2 & pid2=$!
more things
kill "$pid1" "$pid2"
Those are approximations as the shell (most shells) language doesn't give you any better API to handle child processes.
There's no guarantee that $pid1
and/or $pid2
will still refer to the processes that were started earlier if those processes may have died. $pid1
and $pid2
could also be the same (if cmd1
has died by the time cmd2
is started). So kill
could kill the wrong processes.
In practice, it's rarely a problem especially on systems where pids are assigned in sequence as it takes quite some time for pid numbers to wrap. But it can become so when the pid table gets full (like when it's filled with zombie processes) and some attackers can get advantage of that.
add a comment |Â
up vote
7
down vote
Of course. Otherwise a system could only run 32768 processes (or whatever the maximum pid number is on the system) per boot.
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.
You see scripts doing things like:
cmd1 & pid1=$!
something else
cmd2 & pid2=$!
more things
kill "$pid1" "$pid2"
Those are approximations as the shell (most shells) language doesn't give you any better API to handle child processes.
There's no guarantee that $pid1
and/or $pid2
will still refer to the processes that were started earlier if those processes may have died. $pid1
and $pid2
could also be the same (if cmd1
has died by the time cmd2
is started). So kill
could kill the wrong processes.
In practice, it's rarely a problem especially on systems where pids are assigned in sequence as it takes quite some time for pid numbers to wrap. But it can become so when the pid table gets full (like when it's filled with zombie processes) and some attackers can get advantage of that.
add a comment |Â
up vote
7
down vote
up vote
7
down vote
Of course. Otherwise a system could only run 32768 processes (or whatever the maximum pid number is on the system) per boot.
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.
You see scripts doing things like:
cmd1 & pid1=$!
something else
cmd2 & pid2=$!
more things
kill "$pid1" "$pid2"
Those are approximations as the shell (most shells) language doesn't give you any better API to handle child processes.
There's no guarantee that $pid1
and/or $pid2
will still refer to the processes that were started earlier if those processes may have died. $pid1
and $pid2
could also be the same (if cmd1
has died by the time cmd2
is started). So kill
could kill the wrong processes.
In practice, it's rarely a problem especially on systems where pids are assigned in sequence as it takes quite some time for pid numbers to wrap. But it can become so when the pid table gets full (like when it's filled with zombie processes) and some attackers can get advantage of that.
Of course. Otherwise a system could only run 32768 processes (or whatever the maximum pid number is on the system) per boot.
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.
You see scripts doing things like:
cmd1 & pid1=$!
something else
cmd2 & pid2=$!
more things
kill "$pid1" "$pid2"
Those are approximations as the shell (most shells) language doesn't give you any better API to handle child processes.
There's no guarantee that $pid1
and/or $pid2
will still refer to the processes that were started earlier if those processes may have died. $pid1
and $pid2
could also be the same (if cmd1
has died by the time cmd2
is started). So kill
could kill the wrong processes.
In practice, it's rarely a problem especially on systems where pids are assigned in sequence as it takes quite some time for pid numbers to wrap. But it can become so when the pid table gets full (like when it's filled with zombie processes) and some attackers can get advantage of that.
edited Jan 5 at 12:12
answered Jan 5 at 12:05
Stéphane Chazelas
281k53518849
281k53518849
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f414971%2fpid-reuse-possibility-in-linux%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
duplicate? stackoverflow.com/questions/18122592/â¦
â Michael D.
Jan 5 at 11:42
No. Not a duplicate. the process is dead and removed from server. But is there any possibility that the same PID kernel can assign to future processes.
â Athiri
Jan 5 at 11:44
I can only guess - if
cat /proc/sys/kernel/pid_max
is reached, it might start from 2 looking for the next available, unused pid. I'd say yes.â Michael D.
Jan 5 at 11:50
Ok. So in my case PID-2252 will be reused. Thanks Mike.
â Athiri
Jan 5 at 11:58
1
relating: unix.stackexchange.com/q/16883/117549
â Jeff Schaller
Jan 5 at 12:06