• 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
pid vs. Process Serial Number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pid vs. Process Serial Number


  • Subject: pid vs. Process Serial Number
  • From: Brad Peterson <email@hidden>
  • Date: Thu, 21 Sep 2006 04:34:09 -0700 (PDT)

Hi all,

I'm trying to determine if my app was launched by cron
so that I can automate certain actions which would
otherwise require interaction.

So, I figured I'd use getppid(), convert the result to
a psn, use that to get the process' name, and then
check for "cron".

But, I always get a -600 when calling
GetProcessForPID().

Has anyone used this successfully? Alternatively, can
anyone suggest a different approach which might work
better?

Thanks!  (Code below)

B

Calling code:

	pid_t pid = getppid();
	NSString *strAppName = pidToProcessName(pid);

my conversion method:

NSString *pidToProcessName(pid_t pid){
    OSErr err;
    NSString *processName;
	NSString  *result = [NSString string];
	ProcessSerialNumber psn;
    psn.highLongOfPSN = 0;
    psn.lowLongOfPSN = 0;
	err = GetProcessForPID(pid, &psn);
	if (err == noErr) {
        //Get name as CFString, which is bridged to
NSString
        CopyProcessName(&psn, (CFStringRef
*)&processName);
        [processName autorelease];
		result = [NSString stringWithString: processName];
		NSLog(result);
    }
    return result;
}

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: pid vs. Process Serial Number
      • From: Tommy Nordgren <email@hidden>
    • Re: pid vs. Process Serial Number
      • From: Rosyna <email@hidden>
    • Re: pid vs. Process Serial Number
      • From: Jerry Krinock <email@hidden>
    • Re: pid vs. Process Serial Number
      • From: "Finlay Dobbie" <email@hidden>
    • Re: pid vs. Process Serial Number
      • From: Chris Suter <email@hidden>
  • Prev by Date: Re: Using WebKit to display data that's not in HTML
  • Next by Date: Re: pid vs. Process Serial Number
  • Previous by thread: Re: How much does NSObject's bind:toObject:withKeyPath:options: do?
  • Next by thread: Re: pid vs. Process Serial Number
  • Index(es):
    • Date
    • Thread