Process and threads, how to find them
Article Metadata
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.


This code not work whene process have panic or was killed:
So I use antoher if
10 Sep
2009
The article represents how to find processes and threads in your system. Beginner may find it difficult to perform this task. This article has represented methods to do so. The methods like GetProcessListL() and and GetThreadListL() will show you all the processes and thread respectively running in your system. If you want to find some specific process, we can also find it by process' SID. All the methods are shown with their code representation.
At some times, we want to know when our process ends in our application i.e. we need a signal when our process ends, the code for the same is also given. Moreover, the ways and code representation to find processes by name and to find server, mutexes and semaphores are also given.
The beginners who are learing these advanced topics will find this article interesting.