Mac中创建守护进程(Daemon)

创建一个可以执行的脚本 hello.sh

touch /Users/oslivan/test/hello.sh
chmod 755 /Users/oslivan/test/hello.sh
## hello.sh start
for((;;))
do
echo "hello."
sleep 3
done
## hello.sh end

创建一个 plist, 并通过 launchctl 加载

touch /Users/oslivan/Library/LaunchAgents/com.oslivan.test.hello.plist
## com.oslivan.test.hello.plist start
<?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>com.oslivan.test.hello</string>
<key>ProgramArguments</key>
<array>
<string>/Users/oslivan/test/hello.sh</string>
</array>
<key>StandardOutPath</key>
<string>/Users/oslivan/test/logfile.log</string>
<key>StandardErrorPath</key>
<string>/Users/oslivan/test/logfile_error.log</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
## com.oslivan.test.hello.plist end
launchctl load /Users/oslivan/Library/LaunchAgents/com.oslivan.test.hello.plist

测试是否启动成功

ps -ef | grep hello
cd /Users/oslivan/test/ && tail logfile.log

参考

Sample Guide

launchd.plist 语法

launchd 教程

最新文章

  1. git的一些指令
  2. Entity Framework Core 实现读写分离
  3. 关于 Visual Studio 调试 Global 的一点总结
  4. mjrefresh源码分析
  5. php中json_decode()和json_encode()
  6. casperjs配合phantomjs实现自动登录百度,模拟点击等等操作 - 怕虎在线www.ipahoo.com图文教程 - 怕虎在线
  7. select标签操作大全
  8. WebX框架学习笔记之二----框架搭建及请求的发起和处理
  9. BZOJ 2222: [Cqoi2006]猜数游戏【神奇的做法,傻逼题,猜结论】
  10. springboot~基于单元测试的mongodb
  11. 解决Warning: mysql_connect(): Headers and client library minor version mismatch. 警告
  12. 4-1 requests库的安装
  13. 记录tiny6410 jlink 命令行调试linux-2.6.38内核
  14. jsp 假分页的实现
  15. .NET MVC中的防CSRF攻击
  16. OpenCV——图像的深度与通道数讲解
  17. Linq let Concat
  18. java 面试题总结(一)
  19. js搜索算法——二分搜索
  20. 按钮CSS样式

热门文章

  1. linux ubuntu生成pac文件,实现代理
  2. (二)获取Access_token
  3. vs2017安装和使用教程(详细)
  4. tensorflow/threading 用到的一些函数
  5. 05 JS基础DOM
  6. JHipster简介
  7. 单片机课程设计——课程设计之四位加法计算器(2)(C代码)
  8. stm32 HAL库笔记(零)
  9. 分享自己用的php分页类实例源码
  10. DP问题