How to Get the Active Processes Running in iOS

How to get the active processes running in iOS

CPU usage was retrieved here: iOS - Get CPU usage from application

RAM usage seems to be addressed here: Available memory for iPhone OS app

Edit:

Like EricS has pointed out in comments, there seems to be a way to get background tasks: Can we retrieve the applications currently running in iPhone and iPad and How to get information about free memory and running processes in an App Store approved app? (Yes, there is one!)

Get list of currently active processes on iOS device

There are private APIs you can use to list all applications installed on a device (such as described in this question), however you will not be able to submit your application to the App Store if you make use of it.

As for currently running processes, there used to be a way before iOS9, but not anymore:

In iOS 9, the sandbox now prevents a process from accessing the kern.proc, kern.procargs, and kern.procargs2 values for other processes

iOS apps are not permitted to see what other apps are running

https://developer.apple.com/videos/play/wwdc2015-703/

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

Works like a charm:

#import <sys/sysctl.h>

How to get all process info in objective-c under iOS system?

Yes, there is no GetCurrentProcess or GetProcessInformation calls on iOS as Apple would prefer that each application live in it's own "sandbox" and know nothing about other apps running on the phone.

But there may be ways to approximate what you are trying to do.

Here are a few related questions that may help you out:

Can we retrieve the applications currently running in iPhone and iPad

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

How to get the active processes running in iOS

The answers to these questions may point you in the direction you'd like to head towards.

Good luck!

Can we retrieve the applications currently running in iPhone and iPad

You can get a list of running processes and from process ids may be you can figure out which ones are system processes and which one are 3rd party apps, but anyway I don't believe you can use it in application for appstore. (code taken from here)

- (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;
}:


Related Topics



Leave a reply



Submit