This page was last modified 07:34, 12 December 2007.
Process and threads, how to find them
From Forum Nokia Wiki
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; 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
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| RUNINSTALL processes always shown in process list | truf | General Symbian C++ | 12 | 2007-12-17 10:47 |
| Runtime Sockets Creation ??? | priya83 | Symbian Networking & Messaging | 3 | 2006-08-12 18:16 |
| How can I get the command line in app | beta55 | General Symbian C++ | 4 | 2006-03-03 02:22 |
| Midlet crashes with Buffer overflow | mopfattn | Mobile Java General | 13 | 2008-02-25 03:09 |
| destroyApp causes KERN-EXEC 3 on 3650 | rawpsycho | Mobile Java General | 2 | 2003-06-24 08:27 |
