我是 Mac OS X 世界的新手,但我有 Windows 开发技能。
我需要开发一个从 Web 服务上传/下载文件的守护程序(在 Windows 上将是 Windows 服务)。
我的问题是:是否可以创建一个用 Objective-C 编写的应用程序作为守护进程(上传/下载)并在操作系统开始使用 launchd 时启动它?或者还有另一种创建守护进程的方法?
谢谢
我是 Mac OS X 世界的新手,但我有 Windows 开发技能。
我需要开发一个从 Web 服务上传/下载文件的守护程序(在 Windows 上将是 Windows 服务)。
我的问题是:是否可以创建一个用 Objective-C 编写的应用程序作为守护进程(上传/下载)并在操作系统开始使用 launchd 时启动它?或者还有另一种创建守护进程的方法?
谢谢
在 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 平台的典型选择,但是从 Ruby、Python 和 Perl 到 AppleScript 到纯 C 或 C++ 的任何其他语言都可以。
不,没有其他(推荐的)方法可以在 Mac 上执行此操作。init.d
-style 脚本在 Mac [或在 Darwin,它是 UNIX 层] 上不起作用。或者,更准确地说,没有运行它们的基础设施。
有关详细信息,请参阅守护程序和服务编程指南。
I don't know if I have understood correctly but I guess you can do it. The next link could be a good start for understand how Daemons work in Objective-C Apple Developer Then here there is a interesting piece of code. It is about GPS but it might be usefull. Also get a look of this github folder.It is a controller for start/stop daemons