0

Why do PIDS under Linux (generally) increment by 4? The only exception I can think of is startup processes run by systemd, which increment by 1 when they are related or 2 otherwise.

How was the number 4 chosen as the default, and is it changeable?

  • What makes you believe that PIDs were incremented by 4? – Hauke Laging Jan 17 '15 at 20:36
  • Run anything on your system, say ps -e. The PID of ps -e will be 4 greater than whatever the last started process was. – user99655 Jan 17 '15 at 20:58
4

PIDs are increased by one.

Start two shells.

shell 1

echo $$
# we assume 1234 as output

shell 2

strace -f -p 1234 -e trace=clone

shell 1

sleep 1 ; sleep 1

shell 2

# output like
clone(Process 25484 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f4111a029d0) = 25484
[pid 25484] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=25484,si_status=0, si_utime=0, si_stime=0} ---
clone(Process 25485 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f4111a029d0) = 25485
[pid 25485] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=25485,     si_status=0, si_utime=0, si_stime=0} ---
clone(Process 25486 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,child_tidptr=0x7f4111a029d0) = 25486
[pid 25486] +++ exited with 0 +++
| improve this answer | |
2

PIDs increment by one except specific patches like gr-security. If you see an increment by steps of 4, this is probably due to your shell executing some extra commands everytime, for example through the $PROMPT_COMMAND variable.

| improve this answer | |
  • 1
    Mine are incrementing by 2 in bash: if I do a series of ps. When I look into it I see that cd_prompt is starting one process (it calculates the window title), every time the prompt is returned. – ctrl-alt-delor Jan 18 '15 at 1:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.