使用Objective-C的Mac OS X守护进程 - launchd

时间:2012-05-08 22:57:23

标签: objective-c macos launchd launch-daemon

我是Mac OS X世界的新手,但我有Windows开发技能。

我需要开发一个从Web服务上传/下载文件的守护进程(在Windows上将是Windows服务)。

我的问题是:是否有可能创建一个用Objective-C编写的应用程序作为守护进程(上传/下载)并在操作系统开始使用launchd时启动它?或者还有另一种创建守护进程的方法吗?

谢谢

2 个答案:

答案 0 :(得分:4)

在OS X上,这些服务称为LaunchDaemon(系统范围)和LaunchAgent(特定于用户)。您创建一个配置,告诉系统何时启动,运行哪个可执行文件,如何处理stdin,stdout和stderr,传递哪些参数等等。看看这些手册页:

launchd(8)       # the service controlling other services
launchctl(1)     # the command to control services
launchd.plist(5) # the configuration format for services

该守护进程可以用在OS X上运行的任何语言编写。因此,Objective-C是Mac平台的典型选择,但是从Apple,Python到Python,从Python,Python和Perl到纯C或C ++都可以做到。

不,没有其他(推荐)方法在Mac上执行此操作。 init.d - 样式脚本在Mac [或Darwin,它的UNIX层]上不起作用。或者,更准确地说,没有运行它们的基础设施。

有关详细信息,请参阅Daemons and Services Programming Guide

答案 1 :(得分:2)

我不知道我是否理解正确,但我想你可以做到。下一个链接可能是了解Daemons如何在Objective-C中工作的良好开端 Apple Developer 然后这里有一段有趣的代码。 It is about GPS but it might be usefull。还可以看一下这个github文件夹。It is a controller for start/stop daemons