Check if a process is running, if not execute it again in Terminal Is there a way to periodically check if a process is running with (probably with Apple script, or some other shell script) and if not then to execute it in Terminal?

I have a PHP script that is needs to run, but after some time it breaks, so I need to start it again.

Thanks.
In OSX use launchd to to this. launchd will start a command at login or boot and if the process dies it will restart it.

The process is controlled by a .plist file formatted as defined in Apple docs the example in that manual page is for the case you ask for.

  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
   http://www.apple.com/DTDs/PropertyList-1.0.dtd &gt;
   &lt;plist version="1.0"&gt;
   &lt;dict&gt;
        &lt;key&gt;Label&lt;/key&gt;
        &lt;string&gt;com.example.exampled&lt;/string&gt;
        &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
             &lt;string&gt;exampled&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;KeepAlive&lt;/key&gt;
        &lt;true/&gt;
   &lt;/dict&gt;
   &lt;/plist&gt;


If you want to to start when a user logs in the this file goes in ~/Library/LaunchAgents. If when the machine boots then /Library/LaunchDaemons (which can't have access to the GUI)  but this will run as root unless you add a UserName key. (Thanks to @Gordon Davisson for the correction and a reread of Apple definitions)

For ease of setting the .plist up you can use Lingon.app available from the Mac AppStore