Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a simple Hello World tool that runs as a daemon
    primarykey
    data
    text
    <p>I built the Command Line tool (Foundation) template in Xcode. It just logs "Hello World" to the console.There is only one class in it main.m. Here's the code:</p> <blockquote> <pre><code>#import &lt;Foundation/Foundation.h&gt; int main (int argc, const char * argv[]) </code></pre> <p>{</p> <pre><code> @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); } return 0; </code></pre> <p>}</p> </blockquote> <p>Now I want to run it as a daemon and log "Hello World" to the console every 10 seconds. So I moved the product/binary to <em>/tmp</em> on my Mac. I created the following plist for launchd:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//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;helloDaemon&lt;/string&gt; &lt;key&gt;ProgramArguments&lt;/key&gt; &lt;array&gt; &lt;string&gt;/tmp/helloDaemon&lt;/string&gt; &lt;/array&gt; &lt;key&gt;StartInterval&lt;/key&gt; &lt;integer&gt;10&lt;/integer&gt; &lt;/dict&gt; &lt;/plist&gt; </code></pre> <p>I loaded the plist using launchctl, but I do not see any "Hello World"s in the console. Instead, I get this:</p> <pre><code>11/03/2012 00:55:35.141 com.apple.launchd: (helloDaemon) Throttling respawn: Will start in 1 seconds 11/03/2012 00:55:45.141 com.apple.launchd: (helloDaemon) Throttling respawn: Will start in 2 seconds 11/03/2012 00:55:55.140 com.apple.launchd: (helloDaemon) Throttling respawn: Will start in 3 seconds </code></pre> <p>So what's going wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload