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
Solved

How to send Ctrl-C event to childprocess

Posted on 2001-09-07
5
1,678 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
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 100 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

809 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