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?

2
  • What makes you believe that PIDs were incremented by 4? Jan 17, 2015 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, 2015 at 20:58

2 Answers 2

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 +++
3

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.

1
  • 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. Jan 18, 2015 at 1:25

You must log in to answer this question.

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