title: Detect which app is currently running on iOS using sysctl
body: <p>I have currently implemented a simple activity monitor to watch all running processes on iOS. </p>
  
  <p>To retrieve a list of all running processes, I do this:</p>
  
  <pre><code>size_t size;
  struct kinfo_proc *procs = NULL;
  int status;
  NSMutableArray *killedProcesses = [[NSMutableArray alloc] init];
  
  int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
  
  status  = sysctl(mib, 4, NULL, &amp;size, NULL, 0);
  procs   = malloc(size);
  status  = sysctl(mib, 4, procs, &amp;size, NULL, 0);
  
  // now, we have a nice list of processes
  </code></pre>
  
  <p>And if I want more information about a specific process, I'll do:</p>
  
  <pre><code>struct kinfo_proc *proc;
  int mib[5] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pidNum, 0 };
  int count;
  size_t size = 0;
  
  // ask the proc size
  if(sysctl(mib, 4, NULL, &amp;size, NULL, 0) &lt; 0) return -1;
  
  // allocate memory for proc
  proc = (struct kinfo_proc *)malloc(size);
  
  sysctl(mib, 4, proc, &amp;size, NULL, 0);
  </code></pre>
  
  <p>All the extra proc info I want is now stored in <em>proc</em>.  </p>
  
  <p>I notice that apps won't be killed by the OS. Even when an app is not used for a long time (longer than 10 min.) it will remain in the process list. Even when I query what "state" the process has (proc->kp_proc.p_stat), it returns "running".</p>
  
  <p>My question is: does anybody know a method to detect which PID is currently running/actively used (maybe: increasing cpu time? running time? cpu ticks etc.) ??</p>