Whenever I run a command in the terminal on Linux, at runtime, its PID changes.

enter image description here

The command I used after running one program two times at runtime, was ps -l. Why does the program change process ID?

  • To expand on what @roaima said in the answer submitted, you are not checking the PID of the same process. Your are executing a NEW process (in the background, thanks to the & character) each time you put in the command and hit enter. Since they are separate processes, of course they need separate PIDs. – 0xSheepdog Mar 25 '19 at 17:52
  • 1
    Please, don't post images of text. – Kusalananda Mar 25 '19 at 18:00

Each new process (and each new instance of the same named program) has a new Process IDentifier.

The PID is an integer, and when it gets to its maximum value it wraps around back to 1. The PID value (number) is unique for any moment in time.

| improve this answer | |
  • Even tho we are running a same program? – Sawako Kuronuma Mar 25 '19 at 17:50
  • @SawakoKuronuma in your example you are running the same program twice so you have a unique PID for each instance. What is not clear about user roaima's answer? – kemotep Mar 25 '19 at 17:59
  • Just asking whether an id would change if the same program is run at same time,,,nvm Got the anwer already,,thanku. – Sawako Kuronuma Mar 25 '19 at 18:07
  • FWIW, I think Linux may allow PIDs up to 2^22 (PID_MAX_LIMIT). By default it may be 32768, but that can be changed. MacOS definitely has PIDs over 65535. – Stephen Harris Mar 26 '19 at 2:06
  • @StephenHarris thank you. Didn't know about PID_MAX_LIMIT. – roaima Mar 26 '19 at 6:43

Pid - is process id Ppid - is parent process id When you run your program, it gets his own pid, therefore pid changes when you run programm some times. Ppid is not changes, because parent process for program is terminal, from which you ran programs

Maybe parent is not terminal, but your programs has one parent for all, and therefore ppid is not changed

| improve this answer | |

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.