[OS X]: GetPid{ApplicationName}; or, How do I kill it when I don't have the PID#?

I need to set up a routine under OS X that will kill and restart a Macintosh Carbon application that tends to hang. Doing something akin to this in the Terminal:

…doesn’t work because the application is hung.

If I were doing it in person, I could get the PID from “top” and then issue the “kill #” command, but since the PID is going to be different and of unpredictable value, I don’t see any easy way of using that.

Unless there exists an easily accessed routine for obtaining the current PID for an application if you happen to know its name?

Alternatively, is there an osa command that will kill off a hung application, as opposed to telling the application to kindly absent itself?

The application, btw, is FileMaker Pro, and the “hung” condition consists of a modal message box coming up on screen stating that “Communication with the Host has been interrupted and cannot be reestablished” with an “OK” button. (It’s a Jaguar thing. FileMaker is great under 10.1.5, but not so happy with 10.2. Due to middleware I have to run, I’m stuck with 10.2 on this box). Anyway, with that message box up, FileMaker is unresponsive to anything and everything, short of someone reaching over with the mouse and clicking the blasted button.

Hmm, that’s another possibility. Is there an OS X version of “Okey Dokey”, a “pusher of default dialog buttons on unattended computers” kind of utility?

Does OSX have the standard unix ‘ps’ utility? On a unix box, I’d do this by doing somthing like:

kill ‘ps -e |grep <application name> |cut <grab fields to get just the pid>’

Kicking it off automatically at the right (hung) time would be tricky…

-lv

Is there a version of VNC that runs on OS X? I know that it works on X11, but unless you’ve got an X server running, that doesn’t do you any good. You could use that to click the button from a remote computer.

OS X is of the Berkeley Flavor. Try:
kill ps -uxww | grep App | grep -v grep | awk '{print $2}'

With the application name instead of “App”. I just tried that with TextEdit, and it worked for that.

Yep, that works! Thanks! Deader’n a doornail! :slight_smile:

Wow, Mac’s have come a long way.

So have apostophes!

What’s an apostophe? I want one. Do they bite?

ParentalAdvisory: Macs have finally become sane, and we can thank BSD UNIX.

:smiley:

I didn’t entirely follow the OP, but if this is something that happens often, you could set up a cron job that runs that line every five minutes.

Even simpler:
killall applicationname

(I’m not sure if a ‘killall’ command exists under OSX, but it does under most unix flavours, and it works just like that - kill all instances of an application with a certain name.)