×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    190

    Exclamation TFindProcess - unbelievable

    Its been three days I am struggling for mere 4-5 lines of code. Can anyone from you tell me why the following code behaves so strangely:


    Code:
    	//    CConsoleBase* console = Console::NewL(_L("test"), TSize(KDefaultConsWidth, KDefaultConsHeight));
    
    	_LIT(KProcessName,"myprocess*");
    
    	TFindProcess find(KProcessName);
    	TFullName name;
    	TInt numProcess = 0;
    
    	while (find.Next(name) == KErrNone)
    	{
    		numProcess++;
    	}
    
    	if(numProcess==0)
    	{
    		// process is not running
    	}
    In the above code, numProcess++ is always called as the code progresses through the while condition block. But numProcess++ should not be called because myprocess.exe is not running.

    If I add the following line at the start of the code then it never goes to the while loop and numProcess++ is not called.

    // CConsoleBase* console = Console::NewL(_L("test"), TSize(KDefaultConsWidth, KDefaultConsHeight));


    HOW CAN THIS BE POSSIBLE ????

    Please try it yourself and you will be amazed!!!
    Last edited by say2paul; 2008-09-18 at 13:03.

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: TFindProcess - unbelievable

    maybe Console causes a leave, so nothing after it will be executed, also check if the process is for some reason left running. For example Y-Tasks::Threads & process plug-in would show you all rpocessed that are currectly running.

  3. #3
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: TFindProcess - unbelievable

    this code works for me:

    Code:
            	// check if my process is running or not
            	TFindProcess finder;
       	    TFullName fullName;
        	    TBool processAlreadyRunning = EFalse;
        	    while (finder.Next(fullName) == KErrNone)
        	        {
        	        if (KErrNotFound != fullName.Find(_L("myprocess")))
        	            {
        	            processAlreadyRunning = ETrue;
        	            break;
        	            }
        	        }
               if (processAlreadyRunning)
                    // it is running
               else
                    // not running
    Amit Kankani
    Nokia Developer Champion

  4. #4
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: TFindProcess - unbelievable

    forgot to add,
    logically your code should work as well, and is infact more optimized... but just give this a try once... (mine is a very old code)

    also do not use _L() like i have, please use KLit method...

    and let know if this works...
    Amit Kankani
    Nokia Developer Champion

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    1,236

    Re: TFindProcess - unbelievable

    Hi,

    I have tried the code it works fine for me.
    Regards,
    Sriky

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    190

    Exclamation Re: TFindProcess - unbelievable

    Quote Originally Posted by symbianyucca View Post
    maybe Console causes a leave, so nothing after it will be executed, also check if the process is for some reason left running. For example Y-Tasks::Threads & process plug-in would show you all rpocessed that are currectly running.
    Yucca, I ensured that myprocess.exe was not running using TaskSpy. The console is not leaving and the code progresses throught the while condition (I debug that)

    What may the problem...?

    I even tried to replace the console line with the User:After(1000000), but it is not working.

    The code only works fine if I include the console line! otherwise it behaves very strange!

    It may be a bug..!!!

  7. #7
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: TFindProcess - unbelievable

    Why don't you try adding some logging to see which handle is being returned.
    I would also look at the exittype and exitreason to make sure something is not holding an old process open.

    For example:

    Code:
    RProcess process;
    if (process.Open(finder) == KErrNone)
      {
      TFileName fn = process.FileName();
      RDebug::Print(_L("File: %S"), &fn);
      process.Close();
      }
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  8. #8
    Registered User
    Join Date
    Jul 2005
    Posts
    190

    Lightbulb Re: TFindProcess - unbelievable

    Thanks Paul,

    I did R&D at my level best and concluded that it might be a BUG with Symbian OS. I am testing it with Nokia 3230.

    The BUG occurs when process name is of 4 characters i.e. if the process name is '1234', 'abcd', etc.

    You or anyone else can try the below code with process name 'myprocess' and '1234' or 'abcd', the result may vary.

    With 'myprocess', the code will never go to the while loop, but with '1234' and 'abcd' the code will always enters the while loop.

    Please note that neither 'myprocess' or '1234' or 'abcd' is running as a process, I just code these names to test the BUG.

    Code:
    	_LIT(KProcessName,"myprocess*");
    
    	TFindProcess find(KProcessName);
    	TFullName name;
    	TInt numProcess = 0;
    
    	while (find.Next(name) == KErrNone)
    	{
    		numProcess++;
    	}
    
    	if(numProcess==0)
    	{
    		// process is not running
    	}
    P.S: Its been 3.5 years I am working in Symbian C++ and I use to avoid copy/paste!!
    Last edited by say2paul; 2008-09-18 at 13:00.

  9. #9
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: TFindProcess - unbelievable

    So I wrote a quick test harness and I can't reproduce on the 6 or so devices I tested against.

    As I said, log out the filenames being reported as matching and see what they are. I suspect there is some process running with names like that.

    Also try with "wxyz" as a name as the examples chosen were from a hex set.
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  10. #10
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: TFindProcess - unbelievable

    did you try my code once ??? see the post... it may give better results !
    Amit Kankani
    Nokia Developer Champion

  11. #11
    Registered User
    Join Date
    Jul 2005
    Posts
    190

    Exclamation Re: TFindProcess - unbelievable

    Quote Originally Posted by amitkankani View Post
    did you try my code once ??? see the post... it may give better results !
    I am out for 2-3 days, till that time we will watch response from other users!!

  12. #12
    Registered User
    Join Date
    Apr 2007
    Location
    Beijing China
    Posts
    9

    Re: TFindProcess - unbelievable

    Does anybody know the answer for this problem? cos I've met the same thing, I need start a console exe from UI program, if I create Console::NewL(), the exe will have blank screen blink, so I remove console, and then start exe for the second time will be failed because of TFindProcess.
    this is my code:
    // Constants
    _LIT(KPROCESSNAME, "myProcess*");

    //_LIT(KTextConsoleTitle, "Console");
    //_LIT(KTextFailed, " failed, leave code = %d");
    //_LIT(KTextPressAnyKey, " [press any key]\n");

    // Global Variables

    //LOCAL_D CConsoleBase* console;

    LOCAL_C void MainL()
    {
    //
    // add your program code here, example code below
    //
    //DoSomeTest();

    CMyTask* task = CMyTask::NewLC();
    task->StartL(1000000);

    //console->Write(_L("Hello, world!\n"));
    CActiveScheduler::Start();

    CleanupStack::PopAndDestroy(task);
    }

    LOCAL_C void DoStartL()
    {
    // Create active scheduler (to run active objects)
    CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    CleanupStack::PushL(scheduler);
    CActiveScheduler::Install(scheduler);

    TInt pcount = 0;
    TFullName processName;
    TFindProcess findProcess(KPROCESSNAME);

    while(findProcess.Next(processName) == KErrNone)
    {
    if (processName != KNullDesC)
    {
    pcount ++;
    }
    else
    break;
    }

    if (pcount < 2)
    {
    MainL();
    }

    // Delete active scheduler
    CleanupStack::PopAndDestroy(scheduler);
    }

    // Global Functions

    GLDEF_C TInt E32Main()
    {
    // Create cleanup stack
    __UHEAP_MARK;
    CTrapCleanup* cleanup = CTrapCleanup::New();

    // // Create output console
    // TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen)))
    // ;
    // if (createError)
    // return createError;

    // Run application code inside TRAP harness, wait keypress when terminated
    TRAPD(mainError, DoStartL())
    ;
    // if (mainError)
    // console->Printf(KTextFailed, mainError);
    // console->Printf(KTextPressAnyKey);
    // console->Getch();

    // delete console;
    delete cleanup;
    __UHEAP_MARKEND;
    return KErrNone;
    }

  13. #13
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: TFindProcess - unbelievable

    sorry but not able to find out what is your problem.
    your exe can have 2 instances by your code.

  14. #14
    Registered User
    Join Date
    Apr 2007
    Location
    Beijing China
    Posts
    9

    Re: TFindProcess - unbelievable

    Quote Originally Posted by skumar_rao View Post
    sorry but not able to find out what is your problem.
    your exe can have 2 instances by your code.

    my exe can't have 2 instances.

  15. #15
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,699

    Re: TFindProcess - unbelievable

    Quote Originally Posted by yuxiaohui View Post
    Does anybody know the answer for this problem? cos I've met the same thing, I need start a console exe from UI program, if I create Console::NewL(), the exe will have blank screen blink, so I remove console
    Removing console is one thing, exiting your code is an other. Are you sure about that your code actually exits? Do you stop the Active Scheduler for example?

Similar Threads

  1. TFindProcess and RProcess in E32Main problem
    By Yotamix in forum Symbian
    Replies: 2
    Last Post: 2008-09-10, 11:24
  2. Replies: 1
    Last Post: 2007-07-06, 12:42
  3. Unbelievable Bug in 6600!
    By vishwas_dot_h in forum Mobile Java General
    Replies: 1
    Last Post: 2004-06-03, 13:53
  4. Unbelievable...
    By lebrowski in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2003-07-07, 09:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×