What's the correct way to stop a background process on Mac OS X?

Posted by mcsheffrey on Stack Overflow See other posts from Stack Overflow or by mcsheffrey
Published on 2010-04-27T18:54:57Z Indexed on 2010/04/29 2:17 UTC
Read the original article Hit count: 255

Filed under:
|
|

I have an application with 2 components: a desktop application that users interact with, and a background process that can be enabled from the desktop application. Once the background process is enabled, it will run as a user launch agent independently of the desktop app.

However, what I'm wondering is what to do when the user disables the background process. At this point I want to stop the background process but I'm not sure what the best approach is. The 3 options that I see are:

  1. Use the 'kill' command.
    • Direct, but not reliable and just seems somewhat "wrong".
  2. Use an NSMachPort to send an exit request from the desktop app to the background process.
    • This is the best approach I've thought of but I've run into an implementation problem (I'll be posting this in a separate query) and I'd like to be sure that the approach is right before going much further.
  3. Something else???

Thank you in advance for any help/insight that you can offer.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about daemon