About cleaning the object from stack
| Tue, 2005-09-20 16:17 | |
|
hi
i have an exe that kills another exe periodically by this code: killprocess() { TFullName aResult; RProcess aProcess; TFindProcess aProcess2(_L("Main*")); while(aProcess2.Next(aResult) == KErrNone) { aProcess.Open(aProcess2); aProcess.Kill(0); aProcess.Close(); } User::After(3000000); killprocess(); } it works only 3 times then it closes but this killprocess function is recursive so it must go on running... then i realized that TFindProcess does overfload the stack..am i wrong? how can i remove this object from stack after the killprocess ends? |
|






I won't attempt to understand what you are trying to do but if you want something to happen on a regular occurrence you should probably be thinking of an active object with a timer which will eliminate reccursion and stack overflow.
Forum posts: 28
now the code is:
TFindProcess* processFinder = new(ELeave) TFindProcess;
while ( processFinder->Next(result) == KErrNone)
{
if (result.Left(4)==_L("Main"))
{
TInt perr = User::LeaveIfError (processHandle.Open (*processFinder, EOwnerThread));
if ( perr == KErrNone )
{
processHandle.Kill(0);
processHandle.Close();
}
}
}
delete processFinder;
processFinder=NULL;
now, it works 3 times then it s closed..Nothing chaenged..
What fulls the stack???
this is the full code of my exe:
// HelloWorld.cpp
//
// Copyright (c) 2000 Symbian Ltd. All rights reserved.
#include "CommonFramework.h"
// do the example
LOCAL_C void doExampleL()
{
dosyakontrol2();
}
////////////////////////////////////////////////////////////////////////////////
LOCAL_C void dosyakontrol2()
{
///////////////////////////////////////////////////////////
aTime.HomeTime(); //
TTimeIntervalSeconds timeIntervalMinutes(10); //
aTime += timeIntervalMinutes; //
User::At(aTime); //
///////////////////////////////////////////////////////////
_LIT(KDir,"C:\\data\\");
_LIT(KMyFile,"C:\\data\\permission.dat");
User::LeaveIfError(fs.Connect());
fs.MkDir(KDir);
TInt err=myFile.Open(fs,KMyFile,EFileRead);
if (err==0)
{
//_LIT(Kyazi,"yaz.txt dosyasi var \n");
//console->Printf(Kyazi);
myFile.Close();
fs.Close();
acmakapama2=oku2();
if(acmakapama2==-1)
dosyakontrol2();
else
{
TFindProcess aProcess2(_L("Main*"));
TFullName aResult;
while(aProcess2.Next(aResult) == KErrNone)
{
RProcess aProcess;
aProcess.Open(aProcess2);
aProcess.Kill(0);
aProcess.Close();
}
_LIT(KExeFileName,"C:\\system\\apps\\telefon\\main.exe");
EikDll::StartExeL(KExeFileName);
dosyakontrol2();
}
}
else if(err==-1)
{
// _LIT(Kyazi,"yaz.txt dosyasi yok \n");
//console->Printf(Kyazi);
myFile.Close();
fs.Close();
TFindProcess* processFinder = new(ELeave) TFindProcess;
while ( processFinder->Next(result) == KErrNone)
{
if (result.Left(4)==_L("Main"))
{
TInt perr = User::LeaveIfError (processHandle.Open (*processFinder, EOwnerThread));
if ( perr == KErrNone )
{
processHandle.Kill(0);
processHandle.Close();
}
}
}
delete processFinder;
processFinder=NULL;
/*
TFindProcess* aProcess2 = new TFindProcess(_L("Main"));
while(aProcess2->Next(aResult) == KErrNone) {
aProcess.Open(*aProcess2);
aProcess.Kill(0);
aProcess.Close();
}
delete aProcess2;
User::After(1500000);
*/
User::After(1500000);
_LIT(KExeFileName,"C:\\system\\apps\\telefon\\main.exe");
EikDll::StartExeL(KExeFileName);
dosyakontrol2();
}
}
////////////////////////////////////////////////////////////////////////////////
LOCAL_C TInt oku2()
{
/// dictionary store with INI information
_LIT(KFileName,"C:\\data\\permission.dat");
User::LeaveIfError(fs.Connect());
CDictionaryStore* store = CDictionaryFileStore::OpenLC(fs, KFileName,TUid::Uid(0x0001));
RDictionaryReadStream stream;
stream.OpenLC (*store, TUid::Uid(0x0002));
acmakapama = stream.ReadInt16L();
CleanupStack::PopAndDestroy(); // readStream
CleanupStack::PopAndDestroy(); // DictionaryStore
fs.Close();
return acmakapama;
}
I
in brief, it periodically closes a process then runs it again...
Forum posts: 1233
The first thing you should do is totally elliminate recursive calling of functions from your program.
You totally misuse it, and seem to try to use them instead of a while loop... a function calling itself again and again for ever.
That will never work. ever.
dont do that.
For each time you call the function, all local variables will be left on the stack from the previous run of the function.
And you call it again and again, and never return from the functions.
You need to totally rethink your design. (and probably read some books on C programming)
Forum posts: 28
Firsly, i know that this is a recursive funtion , it must be as i wanna this exe live for ever...
Now i rearranged this code and add this funtion to the active object.
Now it works PERFECT...
Thanks again...
Forum posts: 1233
recursiveness must have an end, and specially in symbian that have a very small default stack, not recurse to deep. (that is repeatingly calling the function from within the function from within the function from within the function etc.
You are trying to do this in infinity, wich will fill your stack very quickly and crash your program under any OS.
If you want to loop forever, You can make it as you said, as an active object.
or.. to not have to be fancy with symbian specific features and
to teach you some basic C, you could do a while loop....
while(1) {
//loop forever.
}
then you can even make your program well behaved by having a way to quit it without killing the process, by puting some quit check in the while loop...
comon...