How can know a program is started?

Discussion in 'Mac Programming' started by DeDMakar, May 15, 2008.

  1. DeDMakar macrumors member

    Joined:
    Mar 24, 2008
    #1
    HI!!!
    How can know a program is started? and How can catching keydown event? Thanks...
     
  2. yeroen macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #2
    Seeing as the question was posted by a lolcat, perhaps a "oh hai der! im in ur computer execing mah instrukshuns!" popup would be appropriate?
     
  3. Krevnik macrumors 68030

    Krevnik

    Joined:
    Sep 8, 2003
    #3
    Two questions...

    Cocoa/Carbon/Java?
    What app are you trying to know about? If it is yours, you know it started when the code starts executing in main(). If it is a fork(), then the return value of fork() lets you know which one you are in. If it is another app, there are a couple methods you can take.
     
  4. DeDMakar thread starter macrumors member

    Joined:
    Mar 24, 2008
    #4
    Sory!!!
    Cocoa, Obj - C.
    How can know a another program is started? I check if is started loginwindow.app
    And it is possible to catch event that loginwindow.app was closed? Give me example, please.
     
  5. yeroen macrumors 6502a

    yeroen

    Joined:
    Mar 8, 2007
    Location:
    Cambridge, MA
    #5
    Are you starting the process from your program? Then the pid returned from fork() whatever Cocoa fork() wrapper is what you want to know. But I'm assuming that if you know how to spawn processes, you know how to check to see if they're started.

    If you're *not* starting the process yourself, you can always do a popen on a 'ps -ef | grep program name you're looking for' shell command.
     
  6. DeDMakar thread starter macrumors member

    Joined:
    Mar 24, 2008
    #6
    Yes, that's clear, but how to get this list? I have found 2 ways: ps -ef and [[NSWorkspace sharedWorkspace] launchedApplications]. 1 way shows in the list loginwindow.app, when it's on and doesn't work. 2 way doesn't show this application at all. What would you suggest?
     

Share This Page