?
Solved

How to send Ctrl-C event to childprocess

Posted on 2001-09-07
5
Medium Priority
?
1,702 Views
Last Modified: 2011-10-03
I use CreateProcess() to create a new console process.I want to send Ctrl-C event to the child process to stop the child.

I have tried GenerateConsoleCtrlEvent(), but it always returned ERROR_INVALID_HANDLE error.

can anybody give me the right answer.

Thanks.
0
Comment
Question by:walkdan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Expert Comment

by:bkdc
ID: 6464902
That's not the way to do it. First of all, you should search the database for an answer (I gave one a week ago, I think, in this topic). Sadly, I don't remember which.

Quick and simple method

#define WM_KICK_THE_BUCKET WM_USER+1; //whatever

worker function(your thread)

int workerThread(...)
{
  bool killed=FALSE;
  while(!killed)
  {
    //do your job
    ......
    if(PeekMessage(...))
    {
       GetMessage(...);
       if(msg==WM_KICK_THE_BUCKET)
       {
          killed=true;
       }
     }
   }
}

from the main thread:

PostThreadMessage(yourThreadHandle,WM_KICK_THE_BUCKET);


}
0
 
LVL 2

Expert Comment

by:bkdc
ID: 6464953
Oooops, I think I missed the target...sorry.
Let's fix that.
1. I'd like to see some code....
2. Processes created with DETACHED_PROCESS or CREATE_NEW_CONSOLE are not affected by SIGINT or SIGBREAK.
3. GenerateConsoleCtrlEvent requires a groupId; what did you send ?
0
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 6464976
>>I use CreateProcess() to create a new console process.I
>>want to send Ctrl-C event to the child process
>>to stop the child.

'CreateProcess()' fills in a PROCESS_INFORMATION struct that has a 'hProcess' member. Just use this in a call to 'TerminateProcess()'.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6865863
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "jkr" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6886779
Per recommendation, force-accepted by
Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

771 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