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

**URL:** <https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778>\
**Category:** Factual Questions\
**Created:** [May 12, 2003, 7:42pm UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778 "2003-05-12T19:42:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AHunter3](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ahunter3/32/368_2.png) [@AHunter3](https://boards.straightdope.com/u/AHunter3)\
**Post date:** [May 12, 2003, 7:42pm UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/1 "2003-05-12T19:42:02Z")

</div>

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:

> [@](#):
>
> osascript -e ‘tell application “ApplicationName” to quit’

…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?

---

<div class="post-metadata">

**Author:** ![LordVor](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LordVor](https://boards.straightdope.com/u/LordVor)\
**Post date:** [May 12, 2003, 8:12pm UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/2 "2003-05-12T20:12:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Punoqllads](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Punoqllads](https://boards.straightdope.com/u/Punoqllads)\
**Post date:** [May 12, 2003, 8:28pm UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/3 "2003-05-12T20:28:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Punoqllads](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Punoqllads](https://boards.straightdope.com/u/Punoqllads)\
**Post date:** [May 12, 2003, 9:00pm UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/4 "2003-05-12T21:00:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AHunter3](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ahunter3/32/368_2.png) [@AHunter3](https://boards.straightdope.com/u/AHunter3)\
**Post date:** [May 12, 2003, 10:22pm UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/5 "2003-05-12T22:22:12Z")

</div>

Yep, that works! Thanks! Deader’n a doornail! 🙂

---

<div class="post-metadata">

**Author:** ![ParentalAdvisory](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@ParentalAdvisory](https://boards.straightdope.com/u/ParentalAdvisory)\
**Post date:** [May 12, 2003, 10:54pm UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/6 "2003-05-12T22:54:30Z")

</div>

Wow, Mac’s have come a long way.

---

<div class="post-metadata">

**Author:** ![stockton](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@stockton](https://boards.straightdope.com/u/stockton)\
**Post date:** [May 13, 2003, 2:33am UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/7 "2003-05-13T02:33:19Z")

</div>

So have apostophes!

---

<div class="post-metadata">

**Author:** ![samarm](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@samarm](https://boards.straightdope.com/u/samarm)\
**Post date:** [May 13, 2003, 2:39am UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/8 "2003-05-13T02:39:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [May 13, 2003, 6:37am UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/9 "2003-05-13T06:37:50Z")

</div>

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

😃

---

<div class="post-metadata">

**Author:** ![Bill\_H](https://avatars.discourse-cdn.com/v4/letter/b/a5b964/32.png) [@Bill\_H](https://boards.straightdope.com/u/Bill_H)\
**Post date:** [May 13, 2003, 6:56am UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/10 "2003-05-13T06:56:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Popup](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@Popup](https://boards.straightdope.com/u/Popup)\
**Post date:** [May 13, 2003, 9:39am UTC](https://boards.straightdope.com/t/os-x-getpid-applicationname-or-how-do-i-kill-it-when-i-dont-have-the-pid/174778/11 "2003-05-13T09:39:26Z")

</div>

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