# MacOS X:  GetPid("ApplName"); or, how to autokill a process w/o knowing its PID#?

**URL:** <https://boards.straightdope.com/t/macos-x-getpid-applname-or-how-to-autokill-a-process-w-o-knowing-its-pid/174787>\
**Category:** Factual Questions\
**Created:** [May 12, 2003, 8:11pm UTC](https://boards.straightdope.com/t/macos-x-getpid-applname-or-how-to-autokill-a-process-w-o-knowing-its-pid/174787 "2003-05-12T20:11:49Z")\
**Posts on this page:** 5\
**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, 8:11pm UTC](https://boards.straightdope.com/t/macos-x-getpid-applname-or-how-to-autokill-a-process-w-o-knowing-its-pid/174787/1 "2003-05-12T20:11:49Z")

</div>

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

```auto

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 thang. FileMaker gets along just fine with 10.1.5 but not with 10.2; unfortunately due to the middleware I’m using I’m stuck with Jaguar on this box). 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:** ![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, 9:26pm UTC](https://boards.straightdope.com/t/macos-x-getpid-applname-or-how-to-autokill-a-process-w-o-knowing-its-pid/174787/2 "2003-05-12T21:26:08Z")

</div>

My first duplicate OP!

It’s a hamster plot, I tell you!

---

<div class="post-metadata">

**Author:** ![Cleophus](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Cleophus](https://boards.straightdope.com/u/Cleophus)\
**Post date:** [May 12, 2003, 9:42pm UTC](https://boards.straightdope.com/t/macos-x-getpid-applname-or-how-to-autokill-a-process-w-o-knowing-its-pid/174787/3 "2003-05-12T21:42:59Z")

</div>

You want the command killall - it takes the name of the process you want to kill. Type “man killall” in the Terminal for a full introduction.

---

<div class="post-metadata">

**Author:** ![Morbo](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/morbo/32/389_2.png) [@Morbo](https://boards.straightdope.com/u/Morbo)\
**Post date:** [May 12, 2003, 10:16pm UTC](https://boards.straightdope.com/t/macos-x-getpid-applname-or-how-to-autokill-a-process-w-o-knowing-its-pid/174787/4 "2003-05-12T22:16:01Z")

</div>

I just tried this in 10.2.6 6L60 and it worked:

kill ‘ps -uxww | grep \<Application name\> | grep -v grep | awk ‘{print $2}’’

---

<div class="post-metadata">

**Author:** ![Morbo](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/morbo/32/389_2.png) [@Morbo](https://boards.straightdope.com/u/Morbo)\
**Post date:** [May 12, 2003, 10:26pm UTC](https://boards.straightdope.com/t/macos-x-getpid-applname-or-how-to-autokill-a-process-w-o-knowing-its-pid/174787/5 "2003-05-12T22:26:24Z")

</div>

Didn’t see the other thread, sorry…
