http://kenwublog.com/mac-os-launchd-tuning

Mac下的启动服务主要有三个地方可配置:
1,系统偏好设置->帐户->登陆项
2,/System/Library/StartupItems 和 /Library/StartupItems/
3,launchd 系统初始化进程配置。

前两种优化比较简单,本文主要介绍的是第三种更为复杂的launchd配置优化。
launchd是Mac OS下,用于初始化系统环境的关键进程。类似Linux下的init, rc。

我们先来看一下Mac OS X的启动原理:
1,mac固件激活,初始化硬件,加载BootX引导器。
2,BootX加载内核与内核扩展(kext)。
3,内核启动launchd进程。
4,launchd根据 ?/System/Library/LaunchAgents ,?/System/Library/LaunchDaemons , ?/Library/LaunchDaemons,?Library/LaunchAgents , ~/Library/LaunchAgents?里的plist配置,启动服务守护进程。

看完了Mac OS X的启动原理,我们不难发觉?/System/Library/LaunchAgents ,?/System/Library/LaunchDaemons , ?/Library/LaunchDaemons,?Library/LaunchAgents?五个目录下的plist属性文件是优化系统的关键。

下面再来理解几个基础概念:
/System/Library和/Library和~/Library目录的区别?
/System/Library目录是存放Apple自己开发的软件。
/Library目录是系统管理员存放的第三方软件。
~/Library/是用户自己存放的第三方软件。

LaunchDaemons和LaunchAgents的区别?
LaunchDaemons是用户未登陆前就启动的服务(守护进程)。
LaunchAgents是用户登陆后启动的服务(守护进程)。

上面提到的五个目录下的plist文件格式及每个字段的含义:

Key Description Required
Label The name of the job yes
ProgramArguments Strings to pass to the program when it is executed yes
UserName The job will be run as the given user, who may not necessarily be the one who submitted it to launchd. no
inetdCompatibility Indicates that the daemon expects to be run as if it were launched by?inetd no
Program The path to your executable. This key can save the ProgramArguments key for flags and arguments. no
onDemand A?boolean?flag that defines if a job runs continuously or not no
RootDirectory The job will be?chrooted?into another directory no
ServiceIPC Whether the daemon can speak IPC to launchd no
WatchPaths Allows launchd to start a job based on modifications at a file-system path no
QueueDirectories Similar to WatchPath, a queue will only watch an empty directory for new files no
StartInterval Used to schedule a job that runs on a repeating schedule. Specified as the number of seconds to wait between runs. no
StartCalendarInterval Job scheduling. The?syntax?is similar to?cron. no
HardResourceLimits Controls restriction of the resources consumed by any job no
LowPriorityIO Tells the kernel that this task is of a low priority when doing file system I/O no
Sockets An array can be used to specify what socket the daemon will listen on for launch on demand no

看不懂上面地plist配置吗?没关系,我们的优化策略是完全卸载服务,所以我们不用关心plist里的配置含义。

开始优化

禁用服务,我们需要用到Mac OS提供的一个工具指令-launchctl
launchctl 指令会针对服务设置一个禁用标志,launchd启动时会先检查这个服务是否被禁用,从而确定是否需要启用这个服务。

禁用服务的方法1
先找到禁用标志文件 /var/db/launchd.db/com.apple.launchd/overrides.plist,查看你要禁用的服务是否已被禁用了。
有些服务已被禁用,但未列在overrides.plist里。此时,你还需要检查这个服务的plist文件Label字段是否已经标记为 Disable。

确认这个服务未禁用后,我们就可以通过调用如下命令,来禁用服务:
sudo launchctl unload plist文件路径
sudo launchctl unload -w?plist文件路径
比如,我想禁用spotlight,则输入
sudo launchctl unload?/System/Library/LaunchAgents/com.apple.Spotlight.plist
sudo launchctl unload -w?/System/Library/LaunchAgents/com.apple.Spotlight.plist

禁用完服务以后,重启Mac OS即可生效。

禁用服务的方法2,一种更有效且暴力的方法(推荐)
先卸载服务
sudo launchctl unload /System/Library/LaunchAgents/com.apple.Spotlight.plist
然后将plist文件mv到其他目录备份。重启。搞定。是不是很简单!

我个人比较喜欢这种禁用服务的方式,所以推荐一下。

如果发现服务禁用后,系统或软件出现异常,可以通过如下命令,还原服务:
方法1:
sudo launchctl load -wF?plist文件路径
方法2:
将备份的plist文件mv回原来的文件夹。
sudo launchctl load plist文件路径

注意:系统级服务的禁用要异常小心,请在禁用前google,确保你熟知这个服务的作用。否则可能导致系统无法启动。
最安全的做法就是不要去禁用它了。

当然,用户服务我们还是可以放心禁用的,有问题最多再启用呗。

下面是我禁用的服务列表:
/System/Library/LaunchDaemons/com.apple.metadata.mds.plist (禁用spotlight的前提)
/System/Library/LaunchAgents/com.apple.Spotlight.plist (Spotlight)
/Library/LaunchDaemons/com.google.keystone.daemon.plist ?(Google Software Update)
/Library/LaunchAgents/com.google.keystone.root.agent ?(Google Software Update)
~/Library/LaunchAgents/com.google.keystone.agent.plist?(Google Software Update,用户下的进程不需要加 sudo)
~/Library/LaunchAgents/com.apple.CSConfigDotMacCert-ken.wug\@me.com-SharedServices.Agent.plist (me.com的共享服务,我不用)
/System/Library/LaunchDaemons/org.cups.cupsd.plist (打印机)
/System/Library/LaunchDaemons/org.cups.cups-lpd.plist (打印机)
/System/Library/LaunchDaemons/com.apple.blued.plist (蓝牙)
/System/Library/LaunchAgents/com.apple.AirPortBaseStationAgent.plist (apple无线基站,我没有这个设备)

知道守护进程(服务)名,如何找到对应的plist文件?
将进程(服务)名拷贝,然后到 /System/Library/LaunchAgents ,?/System/Library/LaunchDaemons , ?/Library/LaunchDaemons,?Library/LaunchAgents , ~/Library/LaunchAgents 五个目录里,通过以下命令查找:

ll|grep 进程(服务)名
比如
ll|grep blued
在 ?/System/Library/LaunchDaemons 中找到了它。接下来,请按上面指导的步骤,禁用该服务。

http://blog.csdn.net/testcs_dn/article/details/67634582

Mac OS启动服务优化高级篇(launchd tuning)禁用某些服务的更多相关文章

  1. Mac OS启动服务优化高级篇(launchd tuning)

    Mac下的启动服务主要有三个地方可配置:1,系统偏好设置->帐户->登陆项2,/System/Library/StartupItems 和 /Library/StartupItems/3, ...

  2. Mac OS启动服务优化高级篇

    一.Mac下的启动服务主要三个可配置的地方 1.系统偏好设置->帐户->登陆项 2./System/Library/StartupItems 和 /Library/StartupItems ...

  3. Mac OS X 快捷键(完整篇) 转载

    转载自:http://www.nooidea.com/2011/01/mac-os-x-keyboard-shortcuts.html 快捷键是通过按下键盘上的组合键来调用 Mac OS X 功能的一 ...

  4. 【转】Mac OS X 快捷键(完整篇)

    原文网址:http://www.nooidea.com/2011/01/mac-os-x-keyboard-shortcuts.html 没有写到基本的一些组合,只是一些可能大家不太常用到但及其提高机 ...

  5. Mac OS X 快捷键(完整篇)

    不少朋友提出要求,希望有个「高质量」的列表.其实这样的资源真是太多,平果官网就有 快捷键文档(多国语言版本).于是花了20分钟,浏览了一些网站,整理了点资源放过来供大家参考. 快捷键是通过按下键盘上的 ...

  6. cocos2d-x mac os启动 android helloworld

    工具环境: mac os, jdk, Android Studio, cocos2d-x-3.13.1, ant, android-ndk. 解压coco2d-x后,根目录下有 setup.py, 命 ...

  7. mac下的改装人生——制作mac os 启动盘

    我即将开始对我的mac进行彻底的改造,现在还需要的是一个mac的启动盘或者启动光盘.由于没钱买mac的安装光盘或者安装盘,只能网上下了一个镜像自己做启动盘~ 需要:装有Mac Os的电脑,至少8g的u ...

  8. Mac OS X 下优化 Terminal,一篇就够了!

    先上最终效果图: 目录 目录 1. 相关工具介绍 2. 配置总览 3. 安装步骤 3.1. 安装 iTerm2 3.2. 安装XCode's Command line tools 3.3. 检查 zs ...

  9. mac os 启动服务命令 launchctl

    参考苹果开发者网址 https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Ch ...

随机推荐

  1. 【a703】求逆序对(线段树的解法)

    Time Limit: 10 second Memory Limit: 2 MB 问题描述 给定一个序列a1,a2...an.如果存在i小于j 并且ai大于aj,那么我们称之为逆序对,求给定序列中逆序 ...

  2. 面试无忧之Zookeeper总结心得

    为什么需要分布式系统 l 单机系统已经无法满足业务需要 l 高性能硬件价格昂贵 分布式系统带来哪些问题 l 集群中节点数据一致性问题 l 集群产生分区 l 负载问题 l 幂等性问题 l 可用性问题 l ...

  3. const常量用extern声明定义的问题(extern变量不能在使用类里初始化)

    test.h #ifndef TEST_H_ #define TEST_H //常量声明和定义采取这种方法即可 const int a = 20;  //不报错,因为const变量链接属性默认是内部链 ...

  4. 左右Cwnd::Create()功能出现afxwin1.inl line:21错误的解决方案

    我最近在调试dll时刻,有一种模糊的断言错误,它是由主程序创建MFC 扩张DLL控制出口(从控制继承CWnd分类)时刻,呼叫Create()下列说法错误的功能: watermark/2/text/aH ...

  5. ubuntu 在配置MySQL维修

    第一步 设备MySQL sudo apt-get install mysql-server 第二步骤 构造MySQL 2.1 vim /etc/mysql/my.cnf 到场bind-address ...

  6. 链表Linked List

    链表Linked List 1. 链表 数组是一种顺序表,index与value之间是一种顺序映射,以O(1)O(1)的复杂度访问数据元素.但是,若要在表的中间部分插入(或删除)某一个元素时,需要将后 ...

  7. webpack之font-awesome

    1.安装font-awesome和font-awesome-loader及依赖 git:https://github.com/shakacode/font-awesome-loader npm ins ...

  8. 真的懂了:TCP协议中的三次握手和四次挥手(关闭连接时, 当收到对方的FIN报文时, 仅仅表示对方不在发送数据了, 但是还能接收数据, 己方也未必全部数据都发送对方了。相当于一开始还没接上话不要紧,后来接上话以后得让人把话讲完)

    一.TCP报文格式 下面是TCP报文格式图: (1) 序号, Seq(Sequence number), 占32位,用来标识从TCP源端向目的端发送的字节流,发起方发送数据时对此进行标记. (2) 确 ...

  9. Like关系查询

    比如:有表1.表2两张相,希望通过like进行关联查询 // mysql中使用concat连接字符串 select  t1.id, t1.title, t2.keyword from t1 inner ...

  10. 一言不合就写socket的post和get请求(拼内容,然后发出去即可)

    一言不合就写socket的post和get请求.写个桌面程序,利用java写get和post请求.测试成功: SocketReq.java package com.test.CipherIndex; ...