-1

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?

migrated from apple.stackexchange.com Mar 25 at 17:25

This question came from our site for power users of Apple hardware and software.

  • 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 at 17:52
  • 1
    Please, don't post images of text. – Kusalananda Mar 25 at 18:00
  • got it,,thanks for the explanation.. – Sawako Kuronuma Mar 25 at 18:09
3

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.

  • Even tho we are running a same program? – Sawako Kuronuma Mar 25 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 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 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 at 2:06
  • @StephenHarris thank you. Didn't know about PID_MAX_LIMIT. – roaima Mar 26 at 6:43

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.