Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

GetProcessForPID is deprecated; what to use instead?

I have been using GetProcessForPID to get the ProcessSerialNumber for the running application, as in


ProcessSerialNumber psn;

int pid = [[NSProcessInfo processInfo] processIdentifier];

OSStatus error = GetProcessForPID(pid, &psn);


I then use this ProcessSerialNumber to create an event tap with CGEventTapCreateForPSN.


As of OS X 10.9, GetProcessForPID is deprecated.

What is the recommended replacement function in Cocoa or in Core Foundation?


Best,

-Michiel.

Posted on Jan 11, 2014 12:22 AM

6 replies

Mar 3, 2014 5:15 AM in response to Community User

Observe the NSWorkspaceDidLaunchApplicationNotification notification.

In the callback, get the process serial number as follows:


NSDictionary* dictionary = [notification userInfo];

NSNumber* psnLow = [dictionary valueForKey: @"NSApplicationProcessSerialNumberLow"];

NSNumber* psnHigh = [dictionary valueForKey: @"NSApplicationProcessSerialNumberHigh"];

ProcessSerialNumber psn;

psn.highLongOfPSN = [psnHigh intValue];

psn.lowLongOfPSN = [psnLow intValue];

GetProcessForPID is deprecated; what to use instead?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.