Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jonculloty

macrumors newbie
Original poster
Sep 5, 2009
2
0
Ireland
Hello,

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...

Code:
#!/bin/ksh
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?

Thanks
 
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.
 
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...
 
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:
Code:
/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.
 
Code:
#!/bin/ksh
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?
s

You're missing a closing single-quote for your awk command, after the "$1}" and before the closing back-tick.
 
4) ... 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)

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

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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.