pid vs. Process Serial Number
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