Types of Background Process

  1. login item

  2. xpc service

  3. daemon/agent (也可以叫 mach service)

  4. startup item

login item

login items 是 OS X 对需要开机运行的APP推荐的启动方式,当用户登录之后自动调起程序,配置 login item 有两种方式:

  1) LSSharedFileListInsertItemURL() 或者 系统偏好设置->用户和群组>登录项

    通过这种方式,login item 会被保存在路径: ~/Library/Preferences/com.apple.loginitems.plist

  2) Service Management Framework

    方式1不可以在 sand box 中使用,Service Management Framework 可以,但是他要求 app 有一个 helper 程序。

    helper 程序存放在 app 的 Contents/Library/LoginItems 目录下,app 的主程序通过在运行时调用 SMLoginItemSetEnabled() 函数来设置 helper 程序为自启动程序,helper 程序在自启动后则可以调起其他程序。

    另外,方式2只适用于 app 被保存在 /Applications/ 路径下的情形。

    

xpc service

XPC 是 OS X 下的一种 IPC (进程间通信) 技术, 它实现了权限隔离, 使得 App Sandbox 更加完备。

使用 XPC,可以将 app 拆分为『主进程+XPC服务』的模式,这哥模式的好处是可以实现错误隔离和权限隔离。

xpc service 通过 NSXPCListener 对象来监听从主进程传入的请求,与主进程之间的通信通常是异步的。

xpc service 的生命周期都由 XPC 来进行控制,当 xpc service 在接收消息时 crash 了,其对应的 connection 依然直有效,但是这个未被处理的消息需要主进程重新发送请求。

daemon/agent

daemon 和 agent 都是由 launchd 进程负责启动的后台作业,launchd 是 OS X 系统用户态的第一个进程。

根据安装路径,可以细分为:

  1. ~/Library/LaunchAgents: 每个用户私有的agent

  2. /Library/LaunchAgents: 所有用户共有的agent

  3. /Library/LaunchDaemons: 所有用户共有的 daemon,具有root权限

  4. /System/Library/LaunchAgents: 系统配置的 agent

  5. /System/Library/LaunchDaemons: 系统配置的 daemon

daemon/agent 通过 plist 文件(property list)进行编程并存入上文所描述的路径中。

如何编写和配置 plist,可以参考:

  http://www.launchd.info/

  https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html

注:通过下图可知,当 daemon 调起有 UI 程序时,会以 agent 的权限调起 UI 程序。

startup item

根据官方文档,这个方式将在以后被废弃,有兴趣可以去看官方文档。另外,想找这方面的实例可以去参考 cisco 的 anyconnect,它使用的就是 startup item 来配置程序的自启动。

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/StartupItems.html

其他参考:

http://www.codesec.net/view/219693.html

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/Introduction.html

https://developer.apple.com/library/content/technotes/tn2083/_index.html

https://objccn.io/issue-14-4/

OS X background process的更多相关文章

  1. PPID=1 runs as a background process, rather than being under the direct control of an interactive user

    https://en.wikipedia.org/wiki/Daemon_(computing) [后台进程,非互动] d 结尾 syslogd 系统日志记录 sshd 响应ssh连接请求 In mu ...

  2. ORA-00444: background process DBRM failed while starting

    SQL> startup 报错:ORA-00444: background process DBRM failed while startingORA-00020:maximum number ...

  3. How to change current process to background process

    Situation: there is a script or command is running, but we need to close current box/windows to do o ...

  4. OS X获取process.env.NODE_ENV出错

    原来项目是其它小组在维护,现在我们需要维护部分功能,把项目带到OS X上运行发现 webpack.config.js获取process.env.NODE_ENV变量出错 解决: 根据电脑操作系统平台类 ...

  5. ORA-00445: Background Process "xxxx" Did Not Start After 120 Seconds

    Recent linux kernels have a feature called Address Space Layout Randomization (ASLR).ASLR  is a feat ...

  6. Oracle ABP(Autotask Background Process)

    ABP相当于自动任务与调度程序之间的中介,其主要作用是将自动任务转换成Autotask作业,供调度程序执行.同样重要的是,ABP还维护所有任务执行的历史记录.ABP将其专用资料档案库存储在sysaux ...

  7. ksvcreate: Process(m000) creation failed

    一测试服务器数据库(Oracle Database 10g Release 10.2.0.5.0 - 64bit Production)突然访问不了,检查发现数据库处于挂起模式(hang mode), ...

  8. 【OS】NMON的简介和使用

    [OS]NMON的简介和使用 目前NMON已开源,以sourceforge为根据地,网址是http://nmon.sourceforge.net. 1. 目的 本文介绍操作系统监控工具Nmon的概念. ...

  9. Linux 进程与信号的概念和操作 linux process and signals

    进程 主要参考: http://www.bogotobogo.com/Linux/linux_process_and_signals.php 译者:李秋豪 信号与进程几乎控制了操作系统的每个任务. 在 ...

随机推荐

  1. 【转】搜索引擎选择: Elasticsearch与Solr

    原文地址:http://i.zhcy.tk/blog/elasticsearchyu-solr/ Elasticsearch简介 Elasticsearch是一个实时的分布式搜索和分析引擎.它可以帮助 ...

  2. Memcached·Redis缓存的基本操作

    Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...

  3. Hadoop伪分布安装配置

    安装环境: 系统:Ubuntu 14.10   64bit hadoop:2.5.1 jdk:1.8.0_11 安装步骤: 一.安装JDK 安装 jdk,并且配置环境以及设置成默认 sudo gedi ...

  4. dfs算法

    一般bfs算法都是使用递归 //下面简单的代码 visited[Max]; dfs(_graph g,int vo){ print(vo); visited[vo]=1 for(int i=0;i&l ...

  5. jquery事件与绑定事件

    1.首先,我们来看一下经常使用的添加事件的方式: <input type="button" id="btn" value="click me!& ...

  6. Modbus软件开发实战指南 之 开发自己的Modbus Poll工具 - 1

    在开发Modbus程序的过程中,也可以发现经常需要使用诸如Modbus Poll和Modbus Slave等辅助调试工具, 用于验证MODBUS通讯消息是否正确.但是,Modbus Poll和Modb ...

  7. JS邮箱验证-正则验证

    <form act="">输入:<input type="text" name="qc" id="qc" ...

  8. 通过 Composer Github Packagist制作发布共享PHP包

    参考来源: https://laravel-china.org/topics/1002 https://rivsen.github.io/post/how-to-publish-package-to- ...

  9. KoaHub.js是基于 Koa.js 平台的 Node.js web 快速开发框架

    koahubjs KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Function, Class, A ...

  10. 1671: [Usaco2005 Dec]Knights of Ni 骑士

    1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 254  Solved: 163 ...