• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Determine if only single instance is running.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determine if only single instance is running.


  • Subject: Re: Determine if only single instance is running.
  • From: "David M. Cotter" <email@hidden>
  • Date: Mon, 22 Feb 2010 11:35:40 -0800

kinda carboney but it think it should work

bool		GetIndProcessType(
	OSType					typeToFind,
	OSType					creatorToFind,
	ProcessSerialNumber			*psnP,
	short					indexS = 0)
{
	ProcessSerialNumber		psn	= { kNoProcess, kNoProcess };
	Boolean				doneB	= FALSE;
	bool				foundB	= false;
	ProcessInfoRec			infoRec;structclr(infoRec);
	OSStatus			err = noErr;

	do {
		ERR(GetNextProcess(&psn));
		ERR(GetProcessInformation(&psn, &infoRec));

		if (err) {
			doneB = true;
		} else if (infoRec.processSignature == creatorToFind && infoRec.processType == typeToFind) {
			doneB = indexS-- == 0;

			if (doneB) {
				foundB = true;
				*psnP = psn;
			}
		}
	} while (!doneB);

	return foundB;
}


bool	IsAlreadyRunning()
{
	bool				runningB = false;
	OSStatus			err = noErr;
	ProcessSerialNumber		myPsn = { 0, kCurrentProcess };
	ProcessSerialNumber		otherPsn;
	Boolean				sameB;

	if (
		GetIndProcessType('APPL', kYourAppSignature, &otherPsn, 0)
		&& SameProcess(&myPsn, &otherPsn, &sameB) == noErr
	) {
		if (sameB) {
			runningB = GetIndProcessType('APPL', kYourAppSignature, &otherPsn, 1);
		} else {
			runningB = true;
		}
	}

	return runningB;
}




On Feb 21, 2010, at 9:59 PM, Poonam Virupaxi Shigihalli wrote:

>
> Hi list,
>
> Is there a way to check an application instance is running. I tried enabling application prohibits multiple instance in info.plist.
> Still i am able to launch multiple instance of the same application.
>
> Thanks,
> Poonam
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Determine if only single instance is running. (From: "Poonam Virupaxi Shigihalli" <email@hidden>)

  • Prev by Date: Re: call ruby scripts from objective c
  • Next by Date: Re: Determine if only single instance is running.
  • Previous by thread: Re: Determine if only single instance is running.
  • Next by thread: Re: Determine if only single instance is running.
  • Index(es):
    • Date
    • Thread