How to create a service process on Mac OS X

Source: Internet
Author: User

There are a total of 4 background process types on Mac. For details, refer to designing daemons and services. You can use launch daemon to start the service without relying on users.

Create launch daemon
  • Run xcode to create a simple command line ApplicationWebtwainservice.

    #import <Foundation/Foundation.h> int main(int argc, const char * argv[]){     @autoreleasepool {         // insert code here...        NSLog(@"Hello, World!");     }     while (1)    {        sleep(100);    }    return 0;}
  • Compile the project and put webtwainservice in/Applications/dynamsoft/webtwainservice.

  • Refer to create launch daemons and agents to create a configuration fileCom. dynamsoft. webtwainservice. plist.

    • Standarderrorpath & standardoutpath: Service Log File Path

    • Keepalive. Set to true. OnceWebtwainserviceThe system automatically restarts the service after an exception occurs.

    • Label: A unique value

    • Programarguments: Executable file path

  • The plist configuration file can be stored in the following places:

    • ~ /Library/launchagents

    • /Library/launchagents

    • /Library/launchdaemons

    • /System/library/launchagents

    • /System/library/launchdaemons

  • SetCom. dynamsoft. webtwainservice. plistPut in/Library/launchdaemons.

  • To successfully register a service, you must also modify the directory permission:Sudo chown root/library/launchdaemons/COM. dynamsoft. webtwainservice. plist.

  • EnterSudo launchctlRun launchd

  • Registration ServiceLoad-D system/library/launchdaemons/COM. dynamsoft. webtwainservice. plist. Then we can see that the service is loaded:


  • Enter list to view running processes.


  • Restart the system, and then open the log/var/log/webtwain. log to check whether the service is running:

How to create a service process on Mac OS X

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.