Getting PackageMaker installer to kill stuff...

Discussion in 'Mac Programming' started by jonculloty, Sep 5, 2009.

  1. jonculloty macrumors newbie

    Sep 5, 2009

    I've been using PackageMaker for the last few weeks and really like the tool.
    Now I'd like my package installer to kill any existing process of that type.
    I've tried scripting this as a pre-flight step but it doesn't seem to work as expected...

    pid=`ps -e | egrep nameofmyapp | egrep -v egrep | awk '{print $1}`
    kill -TERM ${pid}
    exit 0
    It runs fine when I execute it standalone from the command line.
    Any ideas on why the script isin't working?
    Or anyone any other suggestions on ways to kill processes from the installer?

  2. mufflon macrumors 6502

    Sep 15, 2006
    Your script might not be runned priveleged?

    I haven't tried packagemaster myself, but out of my mind, this is probably the most likely reason.
  3. jonculloty thread starter macrumors newbie

    Sep 5, 2009
    Hi, thanks for the suggestion. Yes, my file permissions are ok. I can run the script from the console no problem. It actually runs in the installer as well but it does not run the kill command... its puzzling...
  4. larkost macrumors 6502a

    Oct 13, 2007
    The problem is probably that you are not using full paths to commands. When you run on the command line you get a bunch of environmental variables (including a long path) setup for you. In other environments (such as the installer) these might not be setup for you. So when writing scripts you should always use full paths. There are also security considerations that mush this as well.

    Then I have a few other comments:

    1) You are not making sure that only your app gets killed. Right now if anything has your apps name in it it will be killed.

    2) Rather than going through all of that piping, awk will do everything in one go:
    /bin/ps -eo pid,comm | /usr/bin/awk '/WebKitPluginHost/ { print $1 }'
    Note that this does not solve the problem from 1.

    3) Next is the problem that more than one instance of your process may be running.

    4) It is probably a bad idea to do this without warning the user, and then you run into the problem that it might not be the console user who is running the installer (yanking the rug out from under the console user is bad)

    5) You would probably be better servered (minus #4) by just using the 'killall' command, as that will take care of multiple instances, and will only match process whose whole name is what you specify.
  5. chown33 macrumors 604

    Aug 9, 2009
    You're missing a closing single-quote for your awk command, after the "$1}" and before the closing back-tick.
  6. chown33 macrumors 604

    Aug 9, 2009
    The 'kill' (or 'killall') command has no special privilege. If a target process isn't owned by the same uid as the sending process, then the signal is not delivered. man 2 kill

    I second this. killall is definitely the way to go. I only bothered replying to the original post because it was a simple quoting error, not something involving privileges, permissions, pathnames, or PFM.

Share This Page