As I pointed out above, the first problem with your OP code is that 'INT' is not defined anywhere, so your attempt to kill INT, $pid; is just a syntax error.
Are you looking for a win32-only solution or must it be cross platform.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
Win32 only. The two options I know of are socketpair and a file-based semaphore implementation. I'm hoping for something that is simpler than the former, but not quite so brute-force-ish as the latter.
| [reply] |
Well, since fork is essentially just a disguised threads->create, the simplist mechanism is to use a shared variable. This is simplistic, but it demonstrates the principle.
#! perl -slw
use strict;
use threads;
use threads::shared;
my $signal :shared = 0;
my $parent = $$;
print "$$:\tI am the parent.\n";
unless( my $pid = fork){
print "$$:\tI am the child.\n";
lock $signal;
$signal = 1;
exit;
}
print "$$:\tWaiting for the child to signal.\n";
sleep 1 until $signal;
print "The child signalled.";
__END__
c:\test>junk2
1124: I am the parent.
1124: Waiting for the child to signal.
-1912: I am the child.
The child signalled.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
kill INT, $pid;
with this linekill 2, $pid;
I also added use strict to make sure everything else was correct, and the script now runs with no errors.
This does not, however, solve the problem. Per a previous post, kill() was not completely ported to win32. I'm looking at alternatives, but so far all I've found is socketpair. This is a bit heavier than I had hoped for.
The script is for win32 only. If you have any suggestions for alternatives, I would love to hear them. | [reply] [d/l] [select] |
Per a previous post, kill() was not completely ported to win32.
It's a little more complicated than that. As I mentioned forks are threads on win32, so you are trying to signal from one thread of a process to another thread of the same process. But which thread receives that signal? Did the signal handler get cloned?
Whilst Perl emulates signals between real perl processes using win32 message queues, only a very limited number of signals are trappable. Namely, INT, QUIT, TERM, and BREAK. All other values are immediatly translated into TerminateProcess(). Unfortunately this information is not documented anywhere.
If you have any suggestions for alternatives, I would love to hear them.
Um.. look ^^up :)
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |