Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get information about free memory and running processes in an App Store approved app? (Yes, there is one!)

There is an app called "Activity Monitor Touch" in the App Store, which displays background processes as well as free memory.

So there MUST be an public API to access this information. The evidence:

evidence

evidence

I'm already searching for days but can't find any good starting point. How can this app figure all this stuff out without any jailbreaking / hacking / etc.?

Until recently I was sure that something like this is absolutely impossible on iOS.

I've found this code snippet:

- (NSArray *)runningProcesses {      int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};     size_t miblen = 4;      size_t size;     int st = sysctl(mib, miblen, NULL, &size, NULL, 0);      struct kinfo_proc * process = NULL;     struct kinfo_proc * newprocess = NULL;      do {          size += size / 10;         newprocess = realloc(process, size);          if (!newprocess){              if (process){                 free(process);             }              return nil;         }          process = newprocess;         st = sysctl(mib, miblen, process, &size, NULL, 0);      } while (st == -1 && errno == ENOMEM);      if (st == 0){          if (size % sizeof(struct kinfo_proc) == 0){             int nprocess = size / sizeof(struct kinfo_proc);              if (nprocess){                  NSMutableArray * array = [[NSMutableArray alloc] init];                  for (int i = nprocess - 1; i >= 0; i--){                      NSString * processID = [[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_pid];                     NSString * processName = [[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_comm];                      NSDictionary * dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:processID, processName, nil]                                                                          forKeys:[NSArray arrayWithObjects:@"ProcessID", @"ProcessName", nil]];                     [processID release];                     [processName release];                     [array addObject:dict];                     [dict release];                 }                  free(process);                 return [array autorelease];             }         }     }      return nil; } 

But I can't make it run on the iPhone. Xcode doesn't know these symbols: CTL_KERN, KERN_PROC, KERN_PROC_ALL

So of course I must import a header file or library. Does anyone know where these belong to, and how the headers must be imported to make this work?

like image 366
dontWatchMyProfile Avatar asked Nov 26 '11 01:11

dontWatchMyProfile


People also ask

How to Check running process in iOS?

Just about every iOS user is probably aware of the task manager by now, which is accessed by double-clicking the Home button. The row of icons across the bottom show what apps are running in the background, and you can flip left or right to see more of them.

How much memory iOS app can use?

Beta versions of iOS 15 and iPadOS 15 now give developers the option of requesting more RAM than the current 5GB maximum per app, with limitations. Apple has always set a cap on how much RAM any one app can use on the iPad, but it's become more of an issue as the devices themselves physically include more.

What data can apps collect from Iphone?

Data Used to Track You And if you see “Contact Info” listed as data an app can collect, that can include your name, address, phone number, email address, and “Any other information that can be used to contact the user outside the app.”


1 Answers

Works like a charm:

#import <sys/sysctl.h> 
like image 61
mackworth Avatar answered Sep 21 '22 16:09

mackworth