Reputation: 1709
I have some perl code which establishes a signal handler:
$SIG{'KILL'} = sub {
....
};
I'm tasked with porting this to windows and I was wondering how I could generate this signal from a C# class.
I saw the Process.Kill
method in the System.Diagnostics.Process
class which seems to allow me to create (via another method) and kill my process, but I can't figure out how get it to send the signal to the perl script.
Upvotes: 3
Views: 7109
Reputation: 7392
As OS, Windows does not support signals. Perl on Windows has emulation of signals for
Ctrl-C
You can send a signal to other thread of the same Perl program.
Upvotes: 1
Reputation: 283733
You're probably thinking of the TERM
signal handler, since KILL
can't be caught. Anyway, Windows doesn't use signals and while it lets you use them, it's within a single thread only, no sending signals to other processes.
You have a variety of other IPC mechanisms though, the usual one for requesting that another process exit gracefully is PostMessage(WM_QUIT)
, but that's really only applicable to graphical applications which Perl scripts usually aren't.
A well supported approach on Windows would be for the parent process to create an event (with the inheritable flag) and pass the handle to the child process, putting it into the environment would be very convenient for Perl. Then the child can perform an action in response to the event.
In addition to window message and kernel events you could use any of sockets, pipes, files, mailslots, process exit codes, shared memory, registry entries, and DDE to communicate between processes on Windows.
Upvotes: 6