Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6855139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:43:11+00:00 2026-05-27T01:43:11+00:00

Using the method described in this question , I can get a list of

  • 0

Using the method described in this question, I can get a list of apps running on an iOS device.
I know PIDs and have access to their kinfo_proc structures.
How can I determine which are foreground processes and which are background (assuming my app is background)?

I tried to find this out base on information in kinfo_proc (see 1st link), via kp_proc.p_priority, but it looks like it is not possible to infer background/foreground state from priority.

I don’t really care if this works correctly for AppStore Review but I would prefer a method that will work without a jailbreak(i.e. Private APIs are ok but which ones?). I want this to work at least on iOS 5

I considered writing a simple MobileSubstrate extension, injecting it into all apps and just hook everyone’s applicationDidBecomeActive, but this requires a jailbreak and is too invasive.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:43:12+00:00Added an answer on May 27, 2026 at 1:43 am

    Well, looks like some usage of nm and IDA on SpringBoardServices binary from simulator helped me on this.
    Following code works on iOS 5.0.1 running on iPod Touch 4, iPhone 4 and iPad1 WiFi(all non-JB)
    Of course you should never try to submit that to AppStore

    - (NSArray*) getActiveApps
    {
    mach_port_t *p;
    void *uikit = dlopen(UIKITPATH, RTLD_LAZY);
    int (*SBSSpringBoardServerPort)() = 
    dlsym(uikit, "SBSSpringBoardServerPort");
    p = (mach_port_t *)SBSSpringBoardServerPort(); 
    dlclose(uikit);
    
    void *sbserv = dlopen(SBSERVPATH, RTLD_LAZY);
    NSArray* (*SBSCopyApplicationDisplayIdentifiers)(mach_port_t* port, BOOL runningApps,BOOL debuggable) = 
    dlsym(sbserv, "SBSCopyApplicationDisplayIdentifiers");
    //SBDisplayIdentifierForPID - protype assumed,verification of params done
    void* (*SBDisplayIdentifierForPID)(mach_port_t* port, int pid,char * result) = 
    dlsym(sbserv, "SBDisplayIdentifierForPID");
    //SBFrontmostApplicationDisplayIdentifier - prototype assumed,verification of params done,don't call this TOO often(every second on iPod touch 4G is 'too often,every 5 seconds is not)
    void* (*SBFrontmostApplicationDisplayIdentifier)(mach_port_t* port,char * result) = 
    dlsym(sbserv, "SBFrontmostApplicationDisplayIdentifier");
    
    
    
    //Get frontmost application
    char frontmostAppS[256];
    memset(frontmostAppS,sizeof(frontmostAppS),0);
    SBFrontmostApplicationDisplayIdentifier(p,frontmostAppS);
    NSString * frontmostApp=[NSString stringWithFormat:@"%s",frontmostAppS];
    //NSLog(@"Frontmost app is %@",frontmostApp);
    //get list of running apps from SpringBoard
    NSArray *allApplications = SBSCopyApplicationDisplayIdentifiers(p,NO, NO);
    //Really returns ACTIVE applications(from multitasking bar)
    /*   NSLog(@"Active applications:");
     for(NSString *identifier in allApplications) {
     // NSString * locName=SBSCopyLocalizedApplicationNameForDisplayIdentifier(p,identifier);
     NSLog(@"Active Application:%@",identifier);
     }
     */ 
    
    //get list of all apps from kernel
    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--){
    
                    int ruid=process[i].kp_eproc.e_pcred.p_ruid;
                    int uid=process[i].kp_eproc.e_ucred.cr_uid;
                    //short int nice=process[i].kp_proc.p_nice;
                    //short int u_prio=process[i].kp_proc.p_usrpri;
                    short int prio=process[i].kp_proc.p_priority;
                    NSString * processID = [[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_pid];
                    NSString * processName = [[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_comm];
    
    
                    BOOL systemProcess=YES;
                    if (ruid==501)
                        systemProcess=NO;
    
    
    
                    char * appid[256];
                    memset(appid,sizeof(appid),0);
                    int intID,intID2;
                    intID=process[i].kp_proc.p_pid,appid;
                    SBDisplayIdentifierForPID(p,intID,appid);/
    
                    NSString * appId=[NSString stringWithFormat:@"%s",appid];
    
                    if (systemProcess==NO)
                    {
                        if ([appId isEqualToString:@""])
                        {
                            //final check.if no appid this is not springboard app
                            NSLog(@"(potentially system)Found process with PID:%@ name %@,isSystem:%d,Priority:%d",processID,processName,systemProcess,prio);
                        }
                        else
                        {
    
                            BOOL isFrontmost=NO;
                            if ([frontmostApp isEqualToString:appId])
                            {
                                isFrontmost=YES;
                            }
                            NSNumber *isFrontmostN=[NSNumber numberWithBool:isFrontmost];
                            NSDictionary * dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:processID, processName,appId,isFrontmostN, nil] 
                                                                                forKeys:[NSArray arrayWithObjects:@"ProcessID", @"ProcessName",@"AppID",@"isFrontmost", nil]];
    
                            NSLog(@"PID:%@, name: %@, AppID:%@,isFrontmost:%d",processID,processName,appId,isFrontmost);
                            [array addObject:dict];
                        }
                    }
                }
    
                free(process);
                return array;
            }
        }
      }
    
        dlclose(sbserv);
    }
    

    Of course 2nd loop is not strictly necessary but I needed non-localized names & PIDs too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the method described by Josh in this question to add a toolbar
when using this method public List<Field> getFieldWithoutId(List<Integer> idSections) throws Exception { try { Connection
I have organised my junit tests using one inner class per method as described:
I'm using an invocation described in this question: Synchronization accross threads / atomic checks?
I've done scaffolding using the method described here http://wiki.rubyonrails.org/rails/pages/ScaffoldGenerator However, I want to know
Should I be using this method of throwing errors: if (isset($this->dbfields[$var])) { return $this->dbfields[$var];
I'm using this method to install an application, but it doesn't put the applications
I find myself using this method a ton to perform actions based on a
I have recently begun using Scala. I've written a DSL in it which can
Consider an ASP.NET MVC 1.0 project using the Areas convention as described on this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.