osx - Creating a simple Hello World tool that runs as a daemon -


i built command line tool (foundation) template in xcode. logs "hello world" console.there 1 class in main.m. here's code:

#import <foundation/foundation.h>  int main (int argc, const char * argv[]) 

{

   @autoreleasepool {         // insert code here...        nslog(@"hello, world!");     }    return 0; 

}

now want run daemon , log "hello world" console every 10 seconds. moved product/binary /tmp on mac. created following plist launchd:

<?xml version="1.0" encoding="utf-8"?> <!doctype plist public "-//apple//dtd plist 1.0//en" "http://www.apple.com/dtds/propertylist-1.0.dtd"> <plist version="1.0"> <dict>     <key>label</key>     <string>hellodaemon</string>     <key>programarguments</key>     <array>         <string>/tmp/hellodaemon</string>     </array>     <key>startinterval</key>     <integer>10</integer> </dict> </plist> 

i loaded plist using launchctl, not see "hello world"s in console. instead, this:

11/03/2012 00:55:35.141 com.apple.launchd: (hellodaemon) throttling respawn: start in 1 seconds 11/03/2012 00:55:45.141 com.apple.launchd: (hellodaemon) throttling respawn: start in 2 seconds 11/03/2012 00:55:55.140 com.apple.launchd: (hellodaemon) throttling respawn: start in 3 seconds 

so what's going wrong?

nslog not working because when launch demon process not have standard io sockets or file handles attached it. have allocated. resource how create proper daemon , how write console , syslog provided in book "advanced mac os x programming (chapter 20) dalrymple & hillegass.

they have define skeleton program addresses io issues highlight. remembered reading while ago , thought maybe someday i'd need it. authors show sample using syslog.h lib using openlog() , syslog() simple communications. show other lower level methods communication files , sockets (for servers, etc).

i appreciate when can tell me how rather reference something, in case, best can do. luck.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -