Parallel instances of Cocoa apps?

  • I need to run multiple copies of a Cocoa application (that
    I am writing) at the same time.  I can do so fine (perhaps
    I should merely say "so far, so good") with straight Unix
    stuff, using C code along the lines of

      system( "<full path to my application's '.app' file> &" );

    That actually seems to work, but I was wondering:

    (1) Is there any way to do this with Cocoa routines, and
        perhaps more importantly,

    (2) Is there any reason *not* to run multiple copies of
        the same Cocoa application?

    There seems to be a way to run multiple copies of the same
    Carbon application, but I couldn't find anything useful
    about Cocoa parallel applications in the XCode docs or
    on the web, or any indication of why Cocoa does not provide
    the same functionality as Carbon.

    (I won't bore you all with whys and wherefores, though I
    will be glad to discuss them offline if anyone cares.
    It may forestall wasting bandwidth if I mention now that
    yes, I do want parallel processes and not just parallel
    threads, and no, multiple documents in one instance of
    the application are not the way I want to go ...)

    --  Jay Reynolds Freeman
    ---------------------
    <Jay_Reynolds_Freeman...>
    http://web.mac.com/jay_reynolds_freeman (personal web site)
  • On Sep 13, 2007, at 10:22 AM, Jay Reynolds Freeman wrote:

    > I need to run multiple copies of a Cocoa application (that
    > I am writing) at the same time.  I can do so fine (perhaps
    > I should merely say "so far, so good") with straight Unix
    > stuff, using C code along the lines of
    >
    > system( "<full path to my application's '.app' file> &" );
    >
    > That actually seems to work, but I was wondering:
    >
    > (1) Is there any way to do this with Cocoa routines, and
    > perhaps more importantly,
    >
    > (2) Is there any reason *not* to run multiple copies of
    > the same Cocoa application?
    >
    > There seems to be a way to run multiple copies of the same
    > Carbon application, but I couldn't find anything useful
    > about Cocoa parallel applications in the XCode docs or
    > on the web, or any indication of why Cocoa does not provide
    > the same functionality as Carbon.

    I am not sure what you mean by this. The OS layer which launches
    apps, Launch Services, is development-API agnostic. You can write an
    app with any mix of Carbon or Cocoa and it does not know the
    difference. And Launch Services also provides an option to launch
    multiple copies of the same app at once.

    Anyway, getting right to the point—you should use the Launch Services
    APIs instead of system(). Many things will work better if you do.

    I will caution that launching the same app more than once can
    sometimes lead to weird side-effects, but you seem determined to do
    it, so it's your call.

    > (I won't bore you all with whys and wherefores, though I
    > will be glad to discuss them offline if anyone cares.
    > It may forestall wasting bandwidth if I mention now that
    > yes, I do want parallel processes and not just parallel
    > threads, and no, multiple documents in one instance of
    > the application are not the way I want to go ...)
    >
    > --  Jay Reynolds Freeman
    > ---------------------
    > <Jay_Reynolds_Freeman...>
    > http://web.mac.com/jay_reynolds_freeman (personal web site)
  • I asked ...

    > I need to run multiple copies of a Cocoa application (that
    > I am writing) at the same time. [...]

    and John Stiles has provided useful comments, for which
    thanks very much.  However, I did not make myself clear.
    What I was trying to ask was whether there were any
    Cocoa-specific troubles one could get into with parallel
    instances of the same application, and if so, whether there
    were any Cocoa APIs to dodge them.

    I am well aware that there are plenty of non-Cocoa-specific
    challenges in running parallel instances of the same
    application.

    Thanks again ...

    --  Jay Reynolds Freeman
    ---------------------
    <Jay_Reynolds_Freeman...>
    http://web.mac.com/jay_reynolds_freeman (personal web site)
  • On 9/13/07, Jay Reynolds Freeman <jay_reynolds_freeman...> wrote:
    > I asked ...
    >
    >> I need to run multiple copies of a Cocoa application (that
    >> I am writing) at the same time. [...]
    >
    > and John Stiles has provided useful comments, for which
    > thanks very much.  However, I did not make myself clear.
    > What I was trying to ask was whether there were any
    > Cocoa-specific troubles one could get into with parallel
    > instances of the same application, and if so, whether there
    > were any Cocoa APIs to dodge them.

    I don't think there are any Cocoa-specific issues with doing so, but
    there are plenty of non-Cocoa specific issues. Off the top of my head:

    * Which instance will be activaed when the user double-clicks your
    app's icon in the Finder?
    * Which instance will be activated when the user opens one of your
    app's documents?
    * Can your users deal with two of your applications in the Dock?

    etc.

    >
    > I am well aware that there are plenty of non-Cocoa-specific
    > challenges in running parallel instances of the same
    > application.

    --
    Clark S. Cox III
    <clarkcox3...>
  • On 9/14/07, Clark Cox <clarkcox3...> wrote:
    > On 9/13/07, Jay Reynolds Freeman <jay_reynolds_freeman...> wrote:
    >> I asked ...
    >>
    >>> I need to run multiple copies of a Cocoa application (that
    >>> I am writing) at the same time. [...]
    >>
    >> and John Stiles has provided useful comments, for which
    >> thanks very much.  However, I did not make myself clear.
    >> What I was trying to ask was whether there were any
    >> Cocoa-specific troubles one could get into with parallel
    >> instances of the same application, and if so, whether there
    >> were any Cocoa APIs to dodge them.
    >
    > I don't think there are any Cocoa-specific issues with doing so, but
    > there are plenty of non-Cocoa specific issues. Off the top of my head:
    >
    > * Which instance will be activaed when the user double-clicks your
    > app's icon in the Finder?

    The instance they double-click.

    > * Which instance will be activated when the user opens one of your
    > app's documents?

    The most recent version (as in version number).

    Anyway you will see possible issues with two or more instances sharing
    preferences (user defaults) files in an uncoordinated fashion. Also
    distributed object, distributed notification, etc. ports / names could
    collide. In fact you likely will see "ServiceProvider" mach port
    failures in the console log even if you don't use DO, etc.

    -Shawn
  • On 9/14/07, Shawn Erickson <shawnce...> wrote:
    > On 9/14/07, Clark Cox <clarkcox3...> wrote:
    >> On 9/13/07, Jay Reynolds Freeman <jay_reynolds_freeman...> wrote:
    >>> I asked ...
    >>>
    >>>> I need to run multiple copies of a Cocoa application (that
    >>>> I am writing) at the same time. [...]
    >>>
    >>> and John Stiles has provided useful comments, for which
    >>> thanks very much.  However, I did not make myself clear.
    >>> What I was trying to ask was whether there were any
    >>> Cocoa-specific troubles one could get into with parallel
    >>> instances of the same application, and if so, whether there
    >>> were any Cocoa APIs to dodge them.
    >>
    >> I don't think there are any Cocoa-specific issues with doing so, but
    >> there are plenty of non-Cocoa specific issues. Off the top of my head:
    >>
    >> * Which instance will be activaed when the user double-clicks your
    >> app's icon in the Finder?
    >
    > The instance they double-click.

    They don't double-click an instance, they double-click a file (or
    bundle in the case of an application). If you've got two instances of
    the same app running, then they both came from the same app on disk.

    >> * Which instance will be activated when the user opens one of your
    >> app's documents?
    >
    > The most recent version (as in version number).

    They're the same app; by definition, they have the same version and
    modification date.

    --
    Clark S. Cox III
    <clarkcox3...>
  • On 9/14/07, Clark Cox <clarkcox3...> wrote:

    >>> * Which instance will be activaed when the user double-clicks your
    >>> app's icon in the Finder?
    >>
    >> The instance they double-click.
    >
    > They don't double-click an instance, they double-click a file (or
    > bundle in the case of an application). If you've got two instances of
    > the same app running, then they both came from the same app on disk.
    >
    >>> * Which instance will be activated when the user opens one of your
    >>> app's documents?
    >>
    >> The most recent version (as in version number).
    >
    > They're the same app; by definition, they have the same version and
    > modification date.

    Ah yeah... I was thought he wanted to have multiple copies of the
    application and run those but I guess he wants to run the same one (on
    disk instance) multiple times. What you outline is correct for that
    scenario as do the ones I listed.

    -Shawn
  • A potential problem is overlap of Mach identifiers.

    I just went into Terminal, and started a second instance of Terminal,
    and here are the messages I received:

    jonh:~ jon$ /Applications/Utilities/Terminal.app/Contents/MacOS/
    Terminal &
    [1] 3952
    jonh:~ jon$ 2007-09-14 11:08:01.596 Terminal[3952] CFLog (0):
    CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port =
    0x2c03, name = 'com.apple.Terminal.ServiceProvider'
    See /usr/include/servers/bootstrap_defs.h for the error codes.
    2007-09-14 11:08:01.598 Terminal[3952] CFLog (99):
    CFMessagePortCreateLocal(): failed to name Mach port
    (com.apple.Terminal.ServiceProvider)

    Presumably, you'd want some way of making sure that instances use
    unique Mach port ids.
  • On Sep 14, 2007, at 8:10 AM, Jonathan Hendry wrote:

    >
    > A potential problem is overlap of Mach identifiers.
    >
    > I just went into Terminal, and started a second instance of
    > Terminal, and here are the messages I received:
    >
    > jonh:~ jon$ /Applications/Utilities/Terminal.app/Contents/MacOS/
    > Terminal &
    > [1] 3952
    > jonh:~ jon$ 2007-09-14 11:08:01.596 Terminal[3952] CFLog (0):
    > CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port =
    > 0x2c03, name = 'com.apple.Terminal.ServiceProvider'
    > See /usr/include/servers/bootstrap_defs.h for the error codes.
    > 2007-09-14 11:08:01.598 Terminal[3952] CFLog (99):
    > CFMessagePortCreateLocal(): failed to name Mach port
    > (com.apple.Terminal.ServiceProvider)
    >
    > Presumably, you'd want some way of making sure that instances use
    > unique Mach port ids.

    I don't believe there's any sort of mechanism for that, though. It's
    just a limitation of the OS, which was not really designed around
    multiple instances of the same app running at once.
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today