Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

SIGINT help

by HaB (Sexton)
on Nov 18, 2000 at 01:00 UTC ( #42282=perlquestion: print w/ replies, xml ) Need Help??
HaB has asked for the wisdom of the Perl Monks concerning the following question:

Hello...

Having some of my first experiences with Win32 Perl. I am running into a problem with a server app I am writing. It is a pre-forking server, per recipe 17.12 in the Cookbook. I'm using the following code in the sub that spawns the child processes, but I am receiving an error that the particular method call I'm using is not supported on this platform. (NT 4.0) I'm using:
my $sigset = POSIX::SigSet->new(SIGINT);

The error I get on that line is:

POSIX::sigemptyset is not implemented on this architecture at line 89

The line of code above is the offending line 89. Is there a way to do this without using the POSIX object method calls? Is there a way to do it on NT period? I am new to NT development, and sadly, most of the perl books are written for unix systems.


Thanks.


-HaB


hword.

Comment on SIGINT help
Download Code
(tye)Re: SIGINT help
by tye (Cardinal) on Nov 18, 2000 at 01:35 UTC

    You can do the old-style:

    $SIG{INT}= sub { ... };
    but that is going to be unreliable under Win32.

    It is a pre-forking server,

    Um, Win32 doesn't support fork(). Perl 5.6.0 has "fork() emulation" which is pretty buggy still. I think your cookbook recipe is going to require some major reworking.

    If I was doing this, I'd replace all of the uses of fork() with appropriate system() calls (or perhaps Win32::Process stuff to keep everything in the same console window) and I'd drop the $SIG{INT} stuff altogether.

            - tye (but my friends call me "Tye")
Re: SIGINT help
by Fastolfe (Vicar) on Nov 18, 2000 at 01:36 UTC
    Perhaps if you could tell us what, exactly, you are trying to do with this code, we could give you a better answer. :)

    If you're just trying to fork, see fork for examples. If you're trying to communicate between a child process and its parent, or for examples on a forking server, see perlipc. NetServer::Generic might have some information as well as the various IO:: modules (such as IO::Socket).

    If you're messing with signals, see perlvar for information on modifying %SIG, but I don't know how portable and functional signals are under NT (or fork for that matter). You may be more interested in pipes or the IPC version of open to do your communication.

Re: SIGINT help
by boo_radley (Parson) on Nov 18, 2000 at 02:22 UTC
    Without knowing exactly what you're trying to do, have you tried Win32::Process? look here for more info.
Re: SIGINT help
by Chmrr (Vicar) on Nov 19, 2000 at 05:23 UTC
    It turns out that this is one of the Things You Can't Do under Win32. Because of how Perl for win32 supports signals and forking (it doesn't, really -- see below) you have to go about it an alternate way. I suggest that you look at the Cookbook's recipe 17.13, "Non-forking servers." I've implemented several servers which had to work under Win32 for various reasons, and found it immensely useful. Unfortunatly, it tends to make the code go everywhere, but there's no easy way around that.

    Win32's treating of signals is abysmal. The bottom line is that you might get killed at any second and there's not a damn thing you can do about it. END{} doesn't get called. %SIG is ignored. Because of this, your process must live in constant fear of its life. To top it off, until 5.6, you couldn't even create your own progeny. 5.6's implementation of fork(), though buggy, does work. But because signal handlers still don't work (like, say, SIGCHLD?) it's not much use.

    As mentioned above, Win32::Process is the "equivalent" of fork. It's less useful because it's a seperate process entirely, though -- you don't even get a chance to give it your old varables (like, say, sockets..) So it isn't useful for servers..


    --
    perl -e 'print "Proud user of $^X$\"$]!$/";'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://42282]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-09-17 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (68 votes), past polls