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. lamp论坛搭建

    1.配置本地yum源   mount 2.安装软件 yum install httpd mariadb mariadb-server   php php-mysql php-gd libjpeg*   ...

  2. php调用API支付接口(使用第三方接口,调用的天工接口。)

    首先访问  https://charging.teegon.com/  注册账号, 找到开发配置   记下client_id和client_secret. 点击 天工开放平台 点击天工收银 点击  S ...

  3. FineUIMvc随笔(4)自定义回发参数与自定义回发

    声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 不能忘却的回发 在上一篇文章中,我们对FineUIMvc中的回发进行了详细描述,目的是为了告诉大家: 1. FineUIMvc中 ...

  4. appium desktop 版本发布

    Appium Desktop is an open source app for Mac, Windows, and Linux which gives you the power of the Ap ...

  5. MySQL学习分享-->查询-->查询的分类

    MySQL的查询可以分为交叉联接.内联接.外联接.自然联接.straight_join 下面对于查询的学习,会用到以下四张表: create table t_commodity_type( `id` ...

  6. 算法模板——LCA(最近公共祖先)

    实现的功能如下——在一个N个点的无环图中,共有N-1条边,M个访问中每次询问两个点的距离 原理——既然N个点,N-1条边,则说明这是一棵树,而且联通.所以以1为根节点DFS建树,然后通过求两点的LCA ...

  7. ubuntu 笔记

    Ubuntu学习之路还很长,做个笔记也不亏 terminal tab 补全忽略大小写: 在 /ect/inputrc文件中添加或修改 'set completion-ignore-case on' U ...

  8. #include<bits/stdc++.h>

    在听学长讲课时看到了#include<bits/stdc++.h>这个头文件,瞬间懵逼辣,百度后了解了 #include<bits/stdc++.h>,包含了C++的所有头文件 ...

  9. HTML5学习笔记<六>: HTML5框架, 背景和实体

    HTML5框架 1. 框架标签(frame): 框架对于页面的设计有着很大的作用 2. 框架集标签(<frameset>): 框架集标签定义如何将窗口分割为框架 每个frameset定义一 ...

  10. Spring Data JPA 实例查询

    一.相关接口方法     在继承JpaRepository接口后,自动拥有了按"实例"进行查询的诸多方法.这些方法主要在两个接口中定义,一是QueryByExampleExecut ...