# moreThanOneInstanceAllowed question

**URL:** <https://forum.juce.com/t/morethanoneinstanceallowed-question/2668>\
**Category:** MacOSX and iOS\
**Created:** [March 19, 2008, 11:45pm UTC](https://forum.juce.com/t/morethanoneinstanceallowed-question/2668 "2008-03-19T23:45:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![igor](https://avatars.discourse-cdn.com/v4/letter/i/dec6dc/32.png) [@igor](https://forum.juce.com/u/igor)\
**Post date:** [March 19, 2008, 11:45pm UTC](https://forum.juce.com/t/morethanoneinstanceallowed-question/2668/1 "2008-03-19T23:45:29Z")

</div>

I need to throw up a dialog box if my app catches another juce app with a particular name running when it starts up.

On windows, that wasn’t hard, I copied the lock code from juce into my moreThanOnceInstanceAllowed() routine:

```auto
InterProcessLock* appLock = 0;
appLock = new InterProcessLock ("juceAppLock_" + theOtherAppName);
if (! appLock->enter(0)){
    //other app found. Put up dialog
   }

```

This works on windows, but the same code on the mac fails. The Lock seems to work, and my dialog is never seen. What’s the correct way to go about doing this on the mac?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 20, 2008, 8:34am UTC](https://forum.juce.com/t/morethanoneinstanceallowed-question/2668/2 "2008-03-20T08:34:13Z")

</div>

There was an interprocesslock problem that I just fixed last week, so get the tip.

And remember that by default the mac prevents more than one instance of an app from even launching, so that might explain it.

---

<div class="post-metadata">

**Author:** ![igor](https://avatars.discourse-cdn.com/v4/letter/i/dec6dc/32.png) [@igor](https://forum.juce.com/u/igor)\
**Post date:** [March 20, 2008, 2:24pm UTC](https://forum.juce.com/t/morethanoneinstanceallowed-question/2668/3 "2008-03-20T14:24:55Z")

</div>

I knew that the MacOS prevents multiple instances from running. What I’m really trying to do is to find out if my (just launched) process is going to be killed because it’s a second instance.

On the Mac, it appears that the interprocesslock wasn’t what was preventing the second process from launching as it did on the PC, but clearly something else was.

Thanks for the tip about the bug fix. I’ll synch up.

---

<div class="post-metadata">

**Author:** ![igor](https://avatars.discourse-cdn.com/v4/letter/i/dec6dc/32.png) [@igor](https://forum.juce.com/u/igor)\
**Post date:** [March 20, 2008, 4:44pm UTC](https://forum.juce.com/t/morethanoneinstanceallowed-question/2668/4 "2008-03-20T16:44:07Z")

</div>

I synched to the svn tip. Still no luck determining if the named process is running.

When I step into appLock-\>enter(0), the first call to

```auto
fcntl (filedesc, F_SETLK, &fl);
```

returns 0, so the enter() returns true. enter() returns false on windows in the same code.

Is this the expected behavior if a similarly named app is running on the Mac?

---

<div class="post-metadata">

**Author:** ![igor](https://avatars.discourse-cdn.com/v4/letter/i/dec6dc/32.png) [@igor](https://forum.juce.com/u/igor)\
**Post date:** [March 20, 2008, 5:41pm UTC](https://forum.juce.com/t/morethanoneinstanceallowed-question/2668/5 "2008-03-20T17:41:24Z")

</div>

More information…

The 1.45 mac code does work if I launch a second instance of _the same_ application. I’m trying to test to see if an application who’s name is set in the InterProcessLock constructor is running.

Could it be that InterProcessLock() isn’t using the lock string passed in the constructor to do its comparisions?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 20, 2008, 5:54pm UTC](https://forum.juce.com/t/morethanoneinstanceallowed-question/2668/6 "2008-03-20T17:54:43Z")

</div>

Oh, I see. It shouldn’t matter about the process - you can see that it uses a shared file which gets created in juce\_posix\_SharedCode.cpp. The filename should be based on whatever string you use.

---

<div class="post-metadata">

**Author:** ![igor](https://avatars.discourse-cdn.com/v4/letter/i/dec6dc/32.png) [@igor](https://forum.juce.com/u/igor)\
**Post date:** [March 20, 2008, 6:39pm UTC](https://forum.juce.com/t/morethanoneinstanceallowed-question/2668/7 "2008-03-20T18:39:56Z")

</div>

Ah. I see what’s going on now. On the mac the lock file is in  
~/Library/Cache/App1/juceAppLock\_App1

When the new process checks for the lock file, it looks in  
~/Library/Cache/App2/juceAppLock\_App1

Obviously, that file is only locked if the full path matches, not just the application name.

I’ll need to be a little trickier to get the lock file status.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 22, 2008, 4:38pm UTC](https://forum.juce.com/t/morethanoneinstanceallowed-question/2668/8 "2008-03-22T16:38:25Z")

</div>

Ah, yes, the temp folder on the mac is application-specific. I’ve checked-in a tweaked version now that should work better.
