Solved

How to send Ctrl-C event to childprocess

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now