Symbian
Symbian OS Library

FAQ-1255 Why can't I use TApaTask to find a process/thread?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Application Architecture
Created: 04/04/2005 Modified: 04/15/2005
Number: FAQ-1255
Platform: Not Applicable

Question:
How do I find running processes/threads?

Answer:
The TApaTask (an instance of a running UI application) class can only be used to search for running UI applications i.e. applications based on the UI framework. Operations can be performed on the task handle to communicate with the application. Other non-UI application tasks i.e. processes and threads cannot be retrieved using this API.

    The code fragment below shows how to get the list of running UI-framework applications, how to get a task handle to a specific instance of an application, and how to kill the application:
    _LIT(KAppToSearch, "MyRunningApp");
    TApaTaskList taskList(iEikonEnv->WsSession());
    TApaTask task = taskList.FindApp(KAppToSearch);
      if(task.Exists())
        {
        // You can also get the application's thread from the task.
        task.KillTask();
        }
            Use the TFindProcess and TFindThread APIs to search for UI and non-UI application process/thread. E.g.

            _LIT(KProcessToSearch, "MyRunningProcess");
            TFullName fullName;
            TInt err = KErrNone;
            TFindProcess findprocess;
            while (err=findprocess.Next(fullName), err==KErrNone)
            {
            if(err=fullName.FindF(KProcessToSearch), err!=KErrNotFound)
            {
            TInt processopenerr = process.Open(aFind);
            if (processopenerr==KErrNone)
            {
            process.Kill(KErrNone);
            process.Close();
            } break;
            }
            }
              Notes:
                1. Embeddable applications are not searchable (depending on how they are run) using the TApaTask class. See FAQ-1129 for more details.
                2. When using the TFindProcess/TFindThread classes to search for a UI application, the process/thread name is generally different to the application's caption name.
                3. If the search for the application's process/thread results in a success, it does not mean that the application is still running. Use the ExitCategory() method to check whether the application has actually terminated or not. A zero length category means that the UI application is still running.