I need an java application to run 24/7 on my mac. Unfortunately the JVM process sometimes gets stuck and thus the java application does not respond anymore.

Is there a possebility to detect if a given process has crashed (or at least is not in a proper running state) and restart this specific process subsequent?

I found

ps aux|grep java

which lists the java process (/usr/bin/java)

Now I need to know how to watch the process state codes and how to restart this particular process in e.g. a shell script.

BTW, the process state is T which means stopped as far as I know.

EDIT: Unfortunately four suggestions didn't work on my machine. I configured an global agent and the jar is starting properly but the process still fails after a certain period of time. Strangely enough the process in activity monitor is not marked as not responding, whereas the context menu of the dock item does (see figure) enter image description here

  • 1
    Did you write the java app and can you explain how you know it is not responding, from the gui or some other way? BTW T doesn't mean it is stuck, it means it has stopped running by a user or it is being traced. – Vic Jan 28 '15 at 17:27
  • No, the java app is just an ordinary jenkins slave .jar which executes some build jobs controlled by the jenkins master CI server. When the jenkins master cant connect to its slave I log into the mac and Activity Monitor.app shows me the jenkins slave process is not responding. – Mahatma_Fatal_Error Jan 28 '15 at 18:06
  • Is there a build log and can you post a piece of it? It may be best to figure out why it is getting stuck and fix that instead. Alternatively, if log is timestamped you may be able to determine if it's stuck by how long it has been since last event...?! – Vic Feb 2 '15 at 10:52

Look at the launchctl which is an interface to launchd daemon.

This daemon main task is to take care of all the system and users daemons. This care includes the possibility to restart a daemon whenever it quits or crashes.

To start with, I advise you to read:

man launchd
man launchctl

Then have a look at one of the simplest plist files used by the system to help you writing your own one to survey JVM and restart it if needed:


Use LaunchD, it's what Mac OS X uses itself for running and monitoring programs. You will need to create a LaunchAgent or LaunchDaemon file, and you can specify that it should get killed and restarted if it reaches the T state.

  • With "specify that it should get killed and restarted..." you mean KeepAlive->true? – Mahatma_Fatal_Error Jan 29 '15 at 9:04
  • @Mahatma_Fatal_Error: exactly, this is the meaning of this boolean. – dan Jan 29 '15 at 9:59

One way maybe using applescript as shown here. Another maybe by the scripting tool sikuli.

Sikuli watches your screen and can respond based on what it sees. So, if it finds Not Responding on the screen it can be scripted to act.

Here is a thread discussing a similar problem to yours which also gives the script below as a solution to their problem. The sikuli website has all the documentation you need. Good luck.

while True:

def Kill(e):


def Open(e):

openApp("/Applications/PrintSmith WS Folder/PrintSmith WS.app")

onAppear(#screenshot of Not Responding Text#,Kill)

onVanish(#screenshot of Printsmith dock icon#,Open)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .