[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Process Group question

Posted on 2000-01-26
5
Medium Priority
?
411 Views
Last Modified: 2013-12-03
I have an MFC based (gui) app, that creates anonymous pipes to a console app that it communicates with.  I have to be able to kill off the console app from the MFC app if the console app gets hung.  This works fine if I communicate directly with the console app, because I can call TerminateProcess() to kill it off if need be.  However, I need to implement support for a console app that has a pre-processing front-end app.  Basically, this pre-processing app parses through the work load, and determines the proper console app to start up to process the work load.  So I need to do this: use CreateProcess() to execute the pre-processing app (which is a console app as well), and that process in turn executes another process.  HOWEVER, if I kill off the pre-processing app, it leaves the workload-processing console app hanging around in the background.  Is there a way to kill off the pre-processing app along with any child processes?  The concept I'm talking about here is a process group.  I tried using CreateProcess() with the CREATE_NEW_PROCESS_GROUP flag, and then using GenerateConsoleCtrlEvent() to send a CTRL_BREAK event to the pre-processing app, but it doesn't work for me.  Any ideas?

thanks
-Matt Smith
0
Comment
Question by:matthewsmith
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 2390787
Isn't that basically the same as you asked in http://www.experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=10203214  ?
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 2000 total points
ID: 2391086
<<Only those processes in the group that share the same console as the calling process receive the signal. In other words, if a process in the group creates a new console, that process does not receive the signal, nor do its descendants>>

GUI has no console, so your console apps do not receive the signal.

Before creating console processes, you have to allocate console in the GUI app:

GUI.cpp:
------
....
AllocConsole();

PROCESS_INFORMATION pi;
CreateProcess("pre-process-console",...,CREATE_NEW_PROCESS_GROUP,...);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);


......
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,pi.dwProcessId);
Sleep(100); // May be useful.
FreeConsole();

----------
PRE-PROCESS.CPP

main()
{
....
   PROCESS_INFORMATION pi;
// Do not allocate the new console.
   CreateProcess(0,"child.exe",0,0,FALSE,0,0,0,&si,&pi);
....
}
0
 

Author Comment

by:matthewsmith
ID: 2391613
To JKR:

Yes, I did ask the same question before.  I'm not sure why it says 'accepted answer', because I don't remember accepting it, and it certainly didn't ever work for me.

To NickRepin:

I was thinking along those lines.  This sounds like a reasonable solution.  I'll try implementing it tomorrow morning and let you know.  Thanks!


cheers,
-Matt Smith
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2391839
I tested it before I posted the answer here.
0
 

Author Comment

by:matthewsmith
ID: 2394042
One other problem I'm having Nick: Everything works fine with the process group, but when I call AllocConsole(), it shows the console window.  Can I have it be hidden some how?  Thanks!

cheers,
-Matt
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question