implement a "kill" with signals 
Author Message
 implement a "kill" with signals

I have been trying to replicate the UNIX version of:

kill(pid, SIGTERM);

were the process receiving the kill has a

signal(SIGTERM, unix_condition_handler);

in order to perform cleanup operations before exiting.

On Windows 2000 I'm doing a:

TerminateProcess(pid, SIGTERM);

But I do not receive the signals in my signal handler function.

Is there any way of doing this on Windows 2000

Thanks,
Peter



Mon, 18 Aug 2003 03:40:21 GMT  
 implement a "kill" with signals

Quote:

> I have been trying to replicate the UNIX version of:

> kill(pid, SIGTERM);

> were the process receiving the kill has a

> signal(SIGTERM, unix_condition_handler);

> in order to perform cleanup operations before exiting.

> On Windows 2000 I'm doing a:

> TerminateProcess(pid, SIGTERM);

> But I do not receive the signals in my signal handler function.

> Is there any way of doing this on Windows 2000

> Thanks,
> Peter

TerminateProcess operates with no cooperation from the target and is the
opposite of "cleanup".  What do you mean by your "signal handler" function.
There are no handlers for TerminateProcess.

Interprocess signaling on Win32 can be done with CreateEvent, SetEvent and
WaitForSingle(orMultiple)Object(s) if no data is being exchanged.  If you need
to exchange data there are 5-10 other techniques that will require some study.

--
Scott McPhillips [VC++ MVP]



Mon, 18 Aug 2003 09:47:58 GMT  
 implement a "kill" with signals

Quote:
> I have been trying to replicate the UNIX version of:

> kill(pid, SIGTERM);

> were the process receiving the kill has a

> signal(SIGTERM, unix_condition_handler);

> in order to perform cleanup operations before exiting.

> On Windows 2000 I'm doing a:

> TerminateProcess(pid, SIGTERM);

> But I do not receive the signals in my signal handler function.

> Is there any way of doing this on Windows 2000

TerminateProcess() is like a mob hit. It's not at all polite. The target is
summarily executed.

Alternatives off the top of my head:

1) If the target process spins a message loop you can define a private
message with RegisterMessage() and send it with SendMessage()

2) your two programs can use a Win32 event. One sets it, the other can have
a background thread that waits on it or it can check the event periodically
in the foreground - see CreateEvent()

3) use named pipe communication - see CallNamedPipe()

4) use socket communication - see send(), recv(), connect(), socket() etc

Regards,
Will



Mon, 18 Aug 2003 09:30:24 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. catch "Abnomal Program Termination" signal

2. Send signal to "Com port", How?

3. Comparisons with value returned from "signal".

4. CHtmlView "Kill" pop-up windows

5. implementing "ls eli*"

6. implementing "complete" comparison

7. Implement a "var.Add(...)"?

8. implementing "trace" in c

9. Question on implementing "repeat...until keypress"?

10. Rules for "implements" in VB

11. "Implement Connection Point..." option is missing

12. How to implement "autometic statement completion"?

 

 
Powered by phpBB® Forum Software