Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6820207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:23:51+00:00 2026-05-26T21:23:51+00:00

So I basically just want to know when a foreign application starts and closes.

  • 0

So I basically just want to know when a foreign application starts and closes.

Right now I’m just running a loop that checks this:

- (BOOL)isRunning:(int)AppPid{
    ProcessSerialNumber psn = { kNoProcess, kNoProcess };
    OSStatus err = GetProcessForPID(AppPid, &psn);
    if ( err != noErr ){
        NSLog(@"Error %d", err);
        return NO;
    }
    return YES;
}

The issue i’m running into is that if I call this function too much (lets say 50 times in a second), it will eventually fail and say the process isn’t running, when it actually is.

This could happen once every 10 minutes, or 5 times in a row, it’s unpredictable.

My question – is there another easy way via Cocoa/Objective-C to determine if a process is running (that doesn’t involve a system task calling ps, as doing that 50 times/second isn’t smart)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:23:52+00:00Added an answer on May 26, 2026 at 9:23 pm

    There’s [NSRunningApplication runningApplicationWithProcessIdentifier:].

    If you want to know when a particular application launches and exits, there are some notifications on NSWorkspace you can listen for, specifically NSWorkspaceDidLaunchApplicationNotification and NSWorkspaceDidTerminateApplicationNotification.

    You can then check the NSWorkspaceApplicationKey of the notification’s userInfo dictionary to retrieve the NSRunningApplication that corresponds to the launched or terminated application, which you can match via bundle ID (or whatever) to determine if it’s the application you’re interested in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I just want to know if its possible to use Nhibernate to migrate
I just want to design this very simple website. Basically there are multiple pages
I'm writing an application that is basically just a preferences dialog, much like the
I am new to networking. I just basically want to know whether we can
Basically, I just want to know how to check if a sortable list is
Our application provides multiple query interfaces that are basically just text inputs. Is there
Basically i just want to do an arbitrary operation using given arguments of arbitrary
Basically I just want to check if one time period overlaps with another. Null
I just basically want to add about 20 and sometimes 80 Proximity Alerts with
I basically want to make things easier by just looping LinkButtons instead of making

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.