×
Namespaces

Variants
Actions

Process and threads, how to find them

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: symbianyucca (30 Mar 2007)
Last edited: hamishwillee (12 Jan 2012)

To find processes you could utilize TFindProcess as illustrated in the GetProcessListL()-function, with it you could use the functions provided by the RProcess to get more information of the process.

void GetProcessListL(void)
{
TFullName res;
TFindProcess find;
while(find.Next(res) == KErrNone)
{
RProcess ph;
ph.Open(find);
 
// here you can use
// functions of the RProcess
// to get more information
// of the selected process.
 
// res will have the process name..
 
ph.Close();
}
}

Similarly you could utilize the TFindThread to find all threads running in the system as shown in GetThreadListL()- example function.

void GetThreadListL(void)
{
TFullName res;
TFindThread find;
while(find.Next(res) == KErrNone)
{
RThread ph;
ph.Open(find);
 
// here you can use
// functions of the RThread
// to get more information
// of the selected thread.
 
// res will have the thread name..
 
ph.Close();
 
}
}

Then if you are interested on finding just some specific process, you could use the following IsProcessRunning()-function:

TBool IsProcessRunning(void)
{
TBool Ret(EFalse);
 
TFileName res;
TFindProcess find;
while(find.Next(res) == KErrNone)
{
RProcess ph;
ph.Open(res);
 
#ifdef __SERIES60_3X__
if(ph.SecureId() == 0x12345678)// SID of the process we are looking for
#else
if(ph.FileName().Find(KtxApplicationFileName) != KErrNotFound)
#endif
{
Ret = ETrue;
 
ph.Close();
break;
}
 
ph.Close();
}
 
return Ret;
}

With this example the process SID is compared in S60 3rd Edition and pre-3rd Edition the applications file name is used to find the process.


Contents

Finding a Process by Name

RProcess proc;
 
_LIT(KMatchName,"SomeProcess*");
 
TFindProcess procName(KMatchName);
 
TInt rc = proc.Open(procName);
 
if (rc != KErrNone)
{
/* open failed, handle error */
}

This code will open the first process it finds that starts with ’SomeProcess’.


Signaling when a Process Ends

The RProcess::Logon() method can be used to wait for a process to complete

RProcess proc;
User::LeaveIfError(proc.Create(MyExeFile));
TRequestStatus istat;
proc.Logon(istat);
proc.Resume();
 
// Thread is executing. Can add code here to run in parallel...
 
// blocks here while process is running
User::WaitForRequest(istat);
 
// Process is ended, you can use proc.ExitType()
// proc.ExitReason() and proc.ExitCategory()
// to get information on how the process ended.


Finding Servers, Mutex and Semaphores

There are some other process-related information can be inquired from Symbian OS APIs, i.e. servers, global mutex and global semaphores. The classes used to get them are TFindServer, TFindMutex and TFindSempahores respectively.

The following example shows how to display the list of servers on the device.

void DisplayServers()
{
_LIT(KPattern, "*");
TFindServer server(KPattern);
TFullName name;
TInt count = 0;
while (server.Next(name) == KErrNone)
{
// Write to the log file in the format of "count - name".
_LIT(KFormattingStr, "%d. %S");
RFileLogger::WriteFormat(KLogDirectory, KLogFile, EFileLoggingModeAppend,
KFormattingStr, count++, &name);
}
}

The output looks like the following:

29/06/2007	11:59:00	0. !FileServer
29/06/2007 11:59:00 1. !Loader
29/06/2007 11:59:00 2. !DmManagerServer
29/06/2007 11:59:00 3. !DmDomainServer
29/06/2007 11:59:00 4. !Windowserver
...

The usage of other classes, such as TFindMutex and TFindSempahore, are similar. First, construct the object with the parameter of the pattern to be searched. Then, call Next() method until it returns zero.


Internal links

This page was last modified on 12 January 2012, at 07:08.
84 page views in the last 30 days.
×