Serge
Serge

Reputation: 2129

How to get PID of foreground app programatically in OS X?

I need to get PID of foreground app programatically(in C or Obj C) in OS X.

How to solve the following problem?

Upvotes: 0

Views: 878

Answers (2)

Spade Johnsson
Spade Johnsson

Reputation: 572

... In a more general way, using the Terminal, entering "top" will display all current active processes, their PID, Uptime, CPU usage [....]...

Upvotes: 0

Gerd K
Gerd K

Reputation: 2993

This should do it:

pid_t pid=NSWorkspace.sharedWorkspace.frontmostApplication.processIdentifier;

Upvotes: 7

Related Questions