Why does PID of apps change/Is there a pattern?












0















Long story short, I'm trying to write a program in Python that will continuously run the command kill [PID of iTunes but from some testing with the command ps aux | grep iTunes | egrep -v "grep|Helper" | awk '{print $2}' and the PID of iTunes changes every time and I can't seem to find a pattern to it. Is there a pattern to it, or way to make it not increment?










share|improve this question


















  • 1





    Why does iTunes keep starting up? This seems like an inefficient method of continually trying to stop the iTunes process.

    – DrZoo
    Feb 21 at 16:56











  • My TV remote logs in a random user and starts playing a song on iTunes whenever we press "play" and there's not a way to fix that without reconfiguring the entire TV remote, which would take hours. This way I can just run this program while we're watching TV and it will practically fix the problem.

    – Rhett Henderson
    Feb 21 at 17:03











  • Interesting. Is putting the computer to sleep not an option? On another note, this is on a Mac right?

    – DrZoo
    Feb 21 at 17:13













  • Yes this is on a Mac, and putting the computer to sleep is an option, and the app still opens even if the computer is put to sleep.

    – Rhett Henderson
    Feb 21 at 17:22






  • 1





    You would probably be better off disabling the iTunes Helper - see apple.stackexchange.com/questions/91710/…

    – Tetsujin
    Feb 21 at 18:49
















0















Long story short, I'm trying to write a program in Python that will continuously run the command kill [PID of iTunes but from some testing with the command ps aux | grep iTunes | egrep -v "grep|Helper" | awk '{print $2}' and the PID of iTunes changes every time and I can't seem to find a pattern to it. Is there a pattern to it, or way to make it not increment?










share|improve this question


















  • 1





    Why does iTunes keep starting up? This seems like an inefficient method of continually trying to stop the iTunes process.

    – DrZoo
    Feb 21 at 16:56











  • My TV remote logs in a random user and starts playing a song on iTunes whenever we press "play" and there's not a way to fix that without reconfiguring the entire TV remote, which would take hours. This way I can just run this program while we're watching TV and it will practically fix the problem.

    – Rhett Henderson
    Feb 21 at 17:03











  • Interesting. Is putting the computer to sleep not an option? On another note, this is on a Mac right?

    – DrZoo
    Feb 21 at 17:13













  • Yes this is on a Mac, and putting the computer to sleep is an option, and the app still opens even if the computer is put to sleep.

    – Rhett Henderson
    Feb 21 at 17:22






  • 1





    You would probably be better off disabling the iTunes Helper - see apple.stackexchange.com/questions/91710/…

    – Tetsujin
    Feb 21 at 18:49














0












0








0








Long story short, I'm trying to write a program in Python that will continuously run the command kill [PID of iTunes but from some testing with the command ps aux | grep iTunes | egrep -v "grep|Helper" | awk '{print $2}' and the PID of iTunes changes every time and I can't seem to find a pattern to it. Is there a pattern to it, or way to make it not increment?










share|improve this question














Long story short, I'm trying to write a program in Python that will continuously run the command kill [PID of iTunes but from some testing with the command ps aux | grep iTunes | egrep -v "grep|Helper" | awk '{print $2}' and the PID of iTunes changes every time and I can't seem to find a pattern to it. Is there a pattern to it, or way to make it not increment?







terminal.app pid






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 21 at 16:30









Rhett HendersonRhett Henderson

1




1








  • 1





    Why does iTunes keep starting up? This seems like an inefficient method of continually trying to stop the iTunes process.

    – DrZoo
    Feb 21 at 16:56











  • My TV remote logs in a random user and starts playing a song on iTunes whenever we press "play" and there's not a way to fix that without reconfiguring the entire TV remote, which would take hours. This way I can just run this program while we're watching TV and it will practically fix the problem.

    – Rhett Henderson
    Feb 21 at 17:03











  • Interesting. Is putting the computer to sleep not an option? On another note, this is on a Mac right?

    – DrZoo
    Feb 21 at 17:13













  • Yes this is on a Mac, and putting the computer to sleep is an option, and the app still opens even if the computer is put to sleep.

    – Rhett Henderson
    Feb 21 at 17:22






  • 1





    You would probably be better off disabling the iTunes Helper - see apple.stackexchange.com/questions/91710/…

    – Tetsujin
    Feb 21 at 18:49














  • 1





    Why does iTunes keep starting up? This seems like an inefficient method of continually trying to stop the iTunes process.

    – DrZoo
    Feb 21 at 16:56











  • My TV remote logs in a random user and starts playing a song on iTunes whenever we press "play" and there's not a way to fix that without reconfiguring the entire TV remote, which would take hours. This way I can just run this program while we're watching TV and it will practically fix the problem.

    – Rhett Henderson
    Feb 21 at 17:03











  • Interesting. Is putting the computer to sleep not an option? On another note, this is on a Mac right?

    – DrZoo
    Feb 21 at 17:13













  • Yes this is on a Mac, and putting the computer to sleep is an option, and the app still opens even if the computer is put to sleep.

    – Rhett Henderson
    Feb 21 at 17:22






  • 1





    You would probably be better off disabling the iTunes Helper - see apple.stackexchange.com/questions/91710/…

    – Tetsujin
    Feb 21 at 18:49








1




1





Why does iTunes keep starting up? This seems like an inefficient method of continually trying to stop the iTunes process.

– DrZoo
Feb 21 at 16:56





Why does iTunes keep starting up? This seems like an inefficient method of continually trying to stop the iTunes process.

– DrZoo
Feb 21 at 16:56













My TV remote logs in a random user and starts playing a song on iTunes whenever we press "play" and there's not a way to fix that without reconfiguring the entire TV remote, which would take hours. This way I can just run this program while we're watching TV and it will practically fix the problem.

– Rhett Henderson
Feb 21 at 17:03





My TV remote logs in a random user and starts playing a song on iTunes whenever we press "play" and there's not a way to fix that without reconfiguring the entire TV remote, which would take hours. This way I can just run this program while we're watching TV and it will practically fix the problem.

– Rhett Henderson
Feb 21 at 17:03













Interesting. Is putting the computer to sleep not an option? On another note, this is on a Mac right?

– DrZoo
Feb 21 at 17:13







Interesting. Is putting the computer to sleep not an option? On another note, this is on a Mac right?

– DrZoo
Feb 21 at 17:13















Yes this is on a Mac, and putting the computer to sleep is an option, and the app still opens even if the computer is put to sleep.

– Rhett Henderson
Feb 21 at 17:22





Yes this is on a Mac, and putting the computer to sleep is an option, and the app still opens even if the computer is put to sleep.

– Rhett Henderson
Feb 21 at 17:22




1




1





You would probably be better off disabling the iTunes Helper - see apple.stackexchange.com/questions/91710/…

– Tetsujin
Feb 21 at 18:49





You would probably be better off disabling the iTunes Helper - see apple.stackexchange.com/questions/91710/…

– Tetsujin
Feb 21 at 18:49










1 Answer
1






active

oldest

votes


















0














There is only one process that will have the same PID each time, on any session or system. That is the init process with will always have the PID 1. Other than that, there is no pattern.



If you use the Homebrew command brew install proctools it will download, build, and install pgrep.



Then you could use pgrep -f <process name> | awk '{print "kill -9 " $1}'



I believe another option would be using pkill with the process name. In that case, I don't think you would have to know the process ID, just the process name. pkill would also be installed if you did the Homebrew command listed above.



If you don't want to install anything, try running this ps axf | grep <process name> | grep -v grep | awk '{print "kill -9 " $1}' | sh. See what it prints out in the shell to see if it will be killing the correct process.






share|improve this answer
























  • launchd is always PID 1, kernel_task is PID 0. Are you thinking nix rather than Mac? The rest, as you say, will always be sequential numbers - in effect 'random'.

    – Tetsujin
    Feb 21 at 18:45






  • 1





    @Tetsujin yeah, I was thinking nix. I think your comment is the better option if that stops it from opening automatically.

    – DrZoo
    Feb 21 at 19:12











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1408218%2fwhy-does-pid-of-apps-change-is-there-a-pattern%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














There is only one process that will have the same PID each time, on any session or system. That is the init process with will always have the PID 1. Other than that, there is no pattern.



If you use the Homebrew command brew install proctools it will download, build, and install pgrep.



Then you could use pgrep -f <process name> | awk '{print "kill -9 " $1}'



I believe another option would be using pkill with the process name. In that case, I don't think you would have to know the process ID, just the process name. pkill would also be installed if you did the Homebrew command listed above.



If you don't want to install anything, try running this ps axf | grep <process name> | grep -v grep | awk '{print "kill -9 " $1}' | sh. See what it prints out in the shell to see if it will be killing the correct process.






share|improve this answer
























  • launchd is always PID 1, kernel_task is PID 0. Are you thinking nix rather than Mac? The rest, as you say, will always be sequential numbers - in effect 'random'.

    – Tetsujin
    Feb 21 at 18:45






  • 1





    @Tetsujin yeah, I was thinking nix. I think your comment is the better option if that stops it from opening automatically.

    – DrZoo
    Feb 21 at 19:12
















0














There is only one process that will have the same PID each time, on any session or system. That is the init process with will always have the PID 1. Other than that, there is no pattern.



If you use the Homebrew command brew install proctools it will download, build, and install pgrep.



Then you could use pgrep -f <process name> | awk '{print "kill -9 " $1}'



I believe another option would be using pkill with the process name. In that case, I don't think you would have to know the process ID, just the process name. pkill would also be installed if you did the Homebrew command listed above.



If you don't want to install anything, try running this ps axf | grep <process name> | grep -v grep | awk '{print "kill -9 " $1}' | sh. See what it prints out in the shell to see if it will be killing the correct process.






share|improve this answer
























  • launchd is always PID 1, kernel_task is PID 0. Are you thinking nix rather than Mac? The rest, as you say, will always be sequential numbers - in effect 'random'.

    – Tetsujin
    Feb 21 at 18:45






  • 1





    @Tetsujin yeah, I was thinking nix. I think your comment is the better option if that stops it from opening automatically.

    – DrZoo
    Feb 21 at 19:12














0












0








0







There is only one process that will have the same PID each time, on any session or system. That is the init process with will always have the PID 1. Other than that, there is no pattern.



If you use the Homebrew command brew install proctools it will download, build, and install pgrep.



Then you could use pgrep -f <process name> | awk '{print "kill -9 " $1}'



I believe another option would be using pkill with the process name. In that case, I don't think you would have to know the process ID, just the process name. pkill would also be installed if you did the Homebrew command listed above.



If you don't want to install anything, try running this ps axf | grep <process name> | grep -v grep | awk '{print "kill -9 " $1}' | sh. See what it prints out in the shell to see if it will be killing the correct process.






share|improve this answer













There is only one process that will have the same PID each time, on any session or system. That is the init process with will always have the PID 1. Other than that, there is no pattern.



If you use the Homebrew command brew install proctools it will download, build, and install pgrep.



Then you could use pgrep -f <process name> | awk '{print "kill -9 " $1}'



I believe another option would be using pkill with the process name. In that case, I don't think you would have to know the process ID, just the process name. pkill would also be installed if you did the Homebrew command listed above.



If you don't want to install anything, try running this ps axf | grep <process name> | grep -v grep | awk '{print "kill -9 " $1}' | sh. See what it prints out in the shell to see if it will be killing the correct process.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 21 at 17:09









DrZooDrZoo

6,02121839




6,02121839













  • launchd is always PID 1, kernel_task is PID 0. Are you thinking nix rather than Mac? The rest, as you say, will always be sequential numbers - in effect 'random'.

    – Tetsujin
    Feb 21 at 18:45






  • 1





    @Tetsujin yeah, I was thinking nix. I think your comment is the better option if that stops it from opening automatically.

    – DrZoo
    Feb 21 at 19:12



















  • launchd is always PID 1, kernel_task is PID 0. Are you thinking nix rather than Mac? The rest, as you say, will always be sequential numbers - in effect 'random'.

    – Tetsujin
    Feb 21 at 18:45






  • 1





    @Tetsujin yeah, I was thinking nix. I think your comment is the better option if that stops it from opening automatically.

    – DrZoo
    Feb 21 at 19:12

















launchd is always PID 1, kernel_task is PID 0. Are you thinking nix rather than Mac? The rest, as you say, will always be sequential numbers - in effect 'random'.

– Tetsujin
Feb 21 at 18:45





launchd is always PID 1, kernel_task is PID 0. Are you thinking nix rather than Mac? The rest, as you say, will always be sequential numbers - in effect 'random'.

– Tetsujin
Feb 21 at 18:45




1




1





@Tetsujin yeah, I was thinking nix. I think your comment is the better option if that stops it from opening automatically.

– DrZoo
Feb 21 at 19:12





@Tetsujin yeah, I was thinking nix. I think your comment is the better option if that stops it from opening automatically.

– DrZoo
Feb 21 at 19:12


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1408218%2fwhy-does-pid-of-apps-change-is-there-a-pattern%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Probability when a professor distributes a quiz and homework assignment to a class of n students.

Aardman Animations

Are they similar matrix