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.
1Why does iTunes keep starting up? This seems like an inefficient method of continually trying to stop the iTunes process. – DrZoo – 2019-02-21T16:56:18.587
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 – 2019-02-21T17:03:27.230
Interesting. Is putting the computer to sleep not an option? On another note, this is on a Mac right? – DrZoo – 2019-02-21T17:13:08.253
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 – 2019-02-21T17:22:56.823
1
You would probably be better off disabling the iTunes Helper - see https://apple.stackexchange.com/questions/91710/itunes-helper-still-running-even-if-it-is-off
– Tetsujin – 2019-02-21T18:49:29.467