This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: GUI Config tool 2.04 bug (REPRODUCEABLE) - not closing child process


I forgot that I brought all my own code to work for reference material.

I made a screen saver killer one time and that's why I made this code!
:)

All documentation for these functions can of course be found in the MSDN
DVD/CD or the website at http://msdn.microsoft.com

You should open the kernel32.dll manually for getting a pointer to the
CreateToolhelp32Snapshot (), Process32First (), Process32Next (), etc.
Why?  Because it won't work on Windows NT/2000 if you don't.  The code
below works fine on Windows 98 but I never got around to using
LoadLibrary() and GetProcAddress () to get the pointers.  If you need
that as well, I can post some code for it.

Look up the documentation on PROCESSENTRY32 because I only fill in the
extension part because I'm killing all SCR programs.

I created this in a rush so I didn't have time to comment it.  The
program was only 135 lines anyhow so it's not really worth commenting!
:)  Besides, I think it's fairly straight forward code.


p.s.
TerminateProcess () should only be called when you can't close the
process normally.  It can cause memory leaks and resource leaks because
it doesn't allow the program to deallocate it's memory or handles.

------------------BEGIN KILL PROC CODE------------------
    HANDLE snapShot;
    PROCESSENTRY32 procEntry;


   snapShot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
   returnValue = (int)snapShot;
   if (returnValue == -1)
   {
      MessageBoxEx (hwnd, "Failed to Get a Snap Shot of the system",
"Failure",
         MB_OK | MB_ICONINFORMATION, 0);
   }

   procEntry.dwSize = sizeof (PROCESSENTRY32);
   if (!Process32First (snapShot, &procEntry))
      MessageBoxEx (hwnd, "Failed to get first Process Information",
"Failure",
         MB_OK | MB_ICONINFORMATION, 0);


   if (strstr (procEntry.szExeFile, ".SCR") != NULL ||
         strstr (procEntry.szExeFile, ".scr") != NULL)
   {
      processID = OpenProcess (PROCESS_TERMINATE, FALSE,
procEntry.th32ProcessID);
      if (processID != NULL)
      {
         returnValue = TerminateProcess (processID, 0xFFFFFFFF);
         if (returnValue)
            WaitForSingleObject(processID, INFINITE);
         else
            MessageBoxEx (hwnd, "Failed to Terminate", "Failure",
               MB_OK | MB_ICONINFORMATION, 0);
         CloseHandle (processID);
      }
      else
         MessageBoxEx (hwnd, "Failed to open Process", "Failure",
            MB_OK | MB_ICONINFORMATION, 0);
   }

   while (Process32Next (snapShot, &procEntry))
   {
      if (strstr (procEntry.szExeFile, ".SCR") != NULL ||
         strstr (procEntry.szExeFile, ".scr") != NULL)
      {
         processID = OpenProcess (PROCESS_TERMINATE, FALSE,
procEntry.th32ProcessID);
         if (processID != NULL)
         {
            returnValue = TerminateProcess (processID, 0xFFFFFFFF);
            if (returnValue)
               WaitForSingleObject(processID, INFINITE);
            else
               MessageBoxEx (hwnd, "Failed to Terminate", "Failure",
                  MB_OK | MB_ICONINFORMATION, 0);
            CloseHandle (processID);
         }
         else
            MessageBoxEx (hwnd, "Failed to open Process", "Failure",
               MB_OK | MB_ICONINFORMATION, 0);
      }
   }
   CloseHandle (snapShot);
-------------------END KILL PROC CODE-------------------


-----Original Message-----
From: ecos-discuss-owner@sources.redhat.com
[mailto:ecos-discuss-owner@sources.redhat.com] On Behalf Of Julian Smart
Sent: Monday, August 13, 2001 10:36 AM
To: Trenton D. Adams; ecos-discuss@sourceware.cygnus.com
Subject: Re: [ECOS] GUI Config tool 2.04 bug (REPRODUCEABLE) - not
closing child process


At 09:08 AM 8/13/01 -0600, you wrote:
>Start building a project and then try and cancel.  The config tool
>doesn't kill make.exe cc1.exe or arm-elf-gcc.exe.
>
>I have some process killing code that I made for windows at home if the
>config tool doesn't have it already.  If you want it, let me know.  You
>should have the process ID already anyhow when the processes are
>spawned, but for some weird reason the config tool might not be able to
>close the child process.  If that happens my code should work.

Thanks -- there was some child-process code in the original CT which I 
should use but I'd also be interested to see your code in case it's
easier 
to understand :-)

Julian
--
Red Hat UK Ltd, Unit 200 Rustat House, 62 Clifton Road, Cambridge, UK.
CB1 
7EG Tel: +44 (1223) 271063


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]