MAC OS start Service optimization Advanced (LAUNCHD tuning)

Source: Internet
Author: User
Tags system log

the start-up service under Mac has three main places to configure:
1, System Preferences-> account-> login Entry
2,/system/library/startupitems and/library/startupitems/
3,LAUNCHD system initialization Process configuration.

The first two optimizations are relatively simple, this paper mainly introduces the third more complex launchd configuration optimization. Launchd is a critical process for initializing the system environment under Mac OS. Similar to Linux under the INIT, RC.

Let's start by looking at how Mac OS x starts:
1,mac firmware Activates, initializes the hardware, and loads the BootX bootloader.
2,bootx load kernel and kernel extensions (kext).
3, the kernel starts the launchd process.
4,launchd according to/system/library/launchagents,/system/library/launchdaemons,/library/launchdaemons, Library/ Launchagents, ~/library/launchagents in the plist configuration, start the service daemon.

After watching Mac OS x start-up principle, we are not difficult to find/system/library/launchagents,/system/library/launchdaemons,/library/launchdaemons, Library /launchagents the Plist property file in five directories is the key to optimizing the system.

Here are some basic concepts to understand:

What are the differences between/system/library and/library and ~/library directories?
The/system/library directory is an apple-developed software store.
The/library directory is a third-party software stored by the system administrator. ~/library/is a third-party software that is stored by users themselves.

The difference between launchdaemons and launchagents?
Launchdaemons is the service (daemon) that the user started before logging in.
Launchagents is the service (daemon) that is started after the user logs on.

Start optimization
To disable the service, we need to use a tool directive provided by Mac OS-launchctl
LThe aunchctl directive sets a disable flag for the service, and when Launchd starts, it checks whether the service is disabled to determine whether the service needs to be enabled.

Method of disabling a service 1
Find the Disable flag file/var/db/launchd.db/com.apple.launchd/overrides.plist first, and see if the service you want to disable has been disabled.
Some services have been disabled, but not listed in Overrides.plist. At this point, you also need to check if the plist file for this service has a label field marked as Disable.

After confirming that the service is not disabled, we can disable the service by invoking the following command:
sudo launchctl unload plist file path
sudo launchctl unload-w plist file path
For example, if I want to disable Spotlight, enter
sudo launchctl unload/system/library/launchagents/com.apple.spotlight.plist
sudo launchctl unload-w/system/library/launchagents/com.apple.spotlight.plist
When the service is disabled, restarting the Mac OS can take effect.

Method 2 for disabling services, a more effective and violent approach (recommended)
Uninstall the service first
sudo launchctl unload/system/library/launchagents/com.apple.spotlight.plist
Then the plist file mv to a different directory backup.
sudo mv/system/library/launchagents/com.apple.spotlight.plist ~/launchd.bak
Reboot . Get. Isn't it simple!

I personally prefer this way of disabling the service, so recommend it.

Finally, if the system or software has an exception after discovering that the service is disabled, you can restore the service with the following command:
Method 1:
sudo launchctl load-wf plist file path
Method 2:
The backup plist file mv back to the original folder.
sudo launchctl load plist file path

Note: Disable system-level services with caution, before disabling Google, make sure you are familiar with the role of this service. Doing so may cause the system to fail to start.
The safest thing to do is not to disable it.
Of course, the user Service we can still be assured that disabled, there is a problem at most again to enable Bai.

Here is the list of services I disabled:
/system/library/launchdaemons/com.apple.metadata.mds.plist (prerequisite for disabling 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, the process under the user does not need to add sudo)
~/library/launchagents/com.apple.csconfigdotmaccert-ken.wug\ @me. Com-sharedservices.agent.plist (me.com Shared Services, I don't have to )
/system/library/launchdaemons/org.cups.cupsd.plist (printer)
/system/library/launchdaemons/org.cups.cups-lpd.plist (printer)
/system/library/launchdaemons/com.apple.blued.plist (Bluetooth)
/system/library/launchagents/com.apple.airportbasestationagent.plist (Apple Wireless Base station, I don't have this device)

By the way, we'll introduce some common processes:
Usereventagent provides event notifications for user area programs.
Tiswitcher IME switch.
Systemuiserver the top menu bar.
Dock Bottom Menu bar ...
Loginwindow window login process, log off or something.
Launchd Needless to say, the system master process.
FONTD font process.
BASH shell Environment Master process, terminal.
Airport Base Station Proxy as the name implies.
Pboard Clipboard is a copy of the paste.
The Ccacheserver Kerberos Tickets Security module caches a number of notes, similar to keys.
Cvmscomp the process associated with OpenGL.
KEXTD Kernel extension Service.
Notifyd in-system messaging services.
Diskarbitrationd disk Monitoring service, in response to USB removable hard drive insertion, removal and other events.
CONFIGD system configuration, status monitoring service.
Syslogd the System log.
DirectoryService file system permission validation.
distnoted external messaging services, such as the iphone, ipad and Mac connections.
NTPD Time service.
Usbmuxd USB support.
Securityd safety key.
Mdnsresponder DNS support.
Kerneleventagent Kernel event Response.
Hidd ergonomic setup Support.
FSEVENTSD fsevent File system event support.
Dynamic_pager virtual memory. Swap
DPD display Port support.
AUTOFSD Automatic mount Network file system.
CORESERVICESD Core Service process.
Coreaudiod the audio service process.
Windowserver UI interface.
OCSPD security protocol support for OCRs.
AUTOFSD Automatic mount file system, configured in/etc/auto_master

How to create a service services process on Mac OS X

On the Mac, there are 4-minute background process types, which you can refer to designing Daemons and Services. To implement the start-up service without relying on the user, you can use launch Daemon.

Create launch Daemon
  • Run Xcode to create a simple command-line application Webtwainservice.

    ?
    123456789101112131415161718 #import <Foundation/Foundation.h> intmain(intargc, constchar* argv[]){     @autoreleasepool {         // insert code here...        NSLog(@"Hello, World!");     }      while(1)    {        sleep(100);    }    return0;}
    • Compile the project and put the Webtwainservice in the /applications/dynamsoft/webtwainservice.

    • Refer to create Launch daemons and Agents, creating a configuration file com.dynamsoft.WebTwainService.plist.

      • Standarderrorpath & standardoutpath: Service log file path

      • KeepAlive. Set to True. Once the Webtwainservice crashes, the service is restarted automatically.

      • Label: A unique value

      • programarguments: Executable file path

    • The places where this plist configuration file can be placed include:

      • ~/library/launchagents

      • /library/launchagents

      • /library/launchdaemons

      • /system/library/launchagents

      • /system/library/launchdaemons

    • Put the com.dynamsoft.WebTwainService.plist under the/library/launchdaemons .

    • To successfully register the service, you must also modify the directory permissions:sudo chown root/library/launchdaemons/com.dynamsoft.webtwainservice.plist.

    • command line input sudo launchctl run launchd

    • Registration Service load-d system/library/launchdaemons/com.dynamsoft.webtwainservice.plist. Then we can see that the service is loaded:

    • Enter list to view the running process

    • Now reboot the system and open the log/var/log/webtwain.log to see if the service is running:

MAC OS start Service optimization Advanced (LAUNCHD tuning)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.