1

我在根进程(守护进程)中使用 Carbon 事件管理器来监视用户进程(我的应用程序)的状态。但我kEventAppLaunched 只为用户进程(我的应用程序)获取午餐根进程(守护进程)。如何获取kEventAppLaunched所有登录用户中的用户进程。

static OSStatus CarbonEventHandler(
                                   EventHandlerCallRef inHandlerCallRef, 
                                   EventRef            inEvent, 
                                   void *              inUserData
                                   )
{
    ProcessSerialNumber psn;
    CFStringRef processName = NULL ;

id lUserData;
if (inUserData) {
    lUserData= (id)inUserData;
}

OSStatus status; 
(void) GetEventParameter(
                         inEvent, 
                         kEventParamProcessID, 
                         typeProcessSerialNumber, 
                         NULL, 
                         sizeof(psn), 
                         NULL, 
                         &psn
                         );
switch ( GetEventKind(inEvent) ) {
    case kEventAppLaunched:

        status =    CopyProcessName(&psn , &processName);
        if (processName != NULL) {

            if([(NSString *)processName isEqualToString:@"myApp"])
            {
                //initialize application


            }

            CFRelease(processName); 
        }

            break;

        default:
            break;
    }
    return noErr;
}
- (void)InstallCarbonEventsForMonitor
{


    static EventHandlerRef sCarbonEventsRef = NULL;
    static const EventTypeSpec kEvents[] = {
        { kEventClassApplication, kEventAppLaunched },
        { kEventClassApplication, kEventAppTerminated }
    };

    if (sCarbonEventsRef == NULL) {
        (void) InstallEventHandler( GetApplicationEventTarget(), (EventHandlerUPP) CarbonEventHandler,
                                   GetEventTypeCount(kEvents),
                                   kEvents,
                                   self,
                                   &sCarbonEventsRef
                                   );

    }

}
4

0 回答 0