1

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?

5
  • 1
    Why does iTunes keep starting up? This seems like an inefficient method of continually trying to stop the iTunes process.
    – DrZoo
    Commented Feb 21, 2019 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. Commented Feb 21, 2019 at 17:03
  • Interesting. Is putting the computer to sleep not an option? On another note, this is on a Mac right?
    – DrZoo
    Commented Feb 21, 2019 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. Commented Feb 21, 2019 at 17:22
  • 1
    You would probably be better off disabling the iTunes Helper - see apple.stackexchange.com/questions/91710/…
    – Tetsujin
    Commented Feb 21, 2019 at 18:49

1 Answer 1

1

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.

2
  • 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
    Commented Feb 21, 2019 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
    Commented Feb 21, 2019 at 19:12

You must log in to answer this question.

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