1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/TSUtils/tprocesskiller.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,72 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <f32file.h>
1.20 +#include <e32debug.h>
1.21 +
1.22 +//This function is used in the test code to kill SCHSVR or MinimalTaskHandler
1.23 +//processes (or some other) when they leftover and may cause OOM condinitons.
1.24 +static TInt KillProcess(const TDesC& aProcessName)
1.25 + {
1.26 + TFullName name;
1.27 + TInt err = KErrNotFound;
1.28 +
1.29 + RDebug::Print(_L("Find and kill \"%S\" process.\n"), &aProcessName);
1.30 +
1.31 + TBuf<64> pattern(aProcessName);
1.32 + TInt length = pattern.Length();
1.33 + pattern += _L("*");
1.34 + TFindProcess procFinder(pattern);
1.35 +
1.36 + while(procFinder.Next(name) == KErrNone)
1.37 + {
1.38 + if(name.Length() > length)
1.39 + {//If found name is a string containing aProcessName string.
1.40 + TChar c(name[length]);
1.41 + if(c.IsAlphaDigit() || c == TChar('_') || c == TChar('-'))
1.42 + {//If the found name is other valid application name starting with aProcessName string.
1.43 + RDebug::Print(_L(":: Process name: \"%S\".\n"), &name);
1.44 + continue;
1.45 + }
1.46 + }
1.47 + RProcess proc;
1.48 +
1.49 + err = proc.Open(name);
1.50 + if(err == KErrNone)
1.51 + {
1.52 +
1.53 + //If the process is alive, terminate it
1.54 + if(proc.ExitType() == EExitPending)
1.55 + {
1.56 + proc.Kill(0);
1.57 + RDebug::Print(_L("\"%S\" process killed.\n"), &name);
1.58 + }
1.59 +
1.60 + //If the process has already died record the error
1.61 + else err = KErrDied;
1.62 +
1.63 + }
1.64 + proc.Close();
1.65 + }
1.66 + return err;
1.67 + }
1.68 +
1.69 +GLDEF_C TInt E32Main()
1.70 + {
1.71 + TFileName name;
1.72 + User::CommandLine(name);
1.73 + return KillProcess(name);
1.74 + }
1.75 +