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

Interrupt Handling

by anshumangoyal (Scribe)
on Sep 02, 2012 at 10:03 UTC ( #991256=perlquestion: print w/replies, xml ) Need Help??
anshumangoyal has asked for the wisdom of the Perl Monks concerning the following question:

I have a number of scripts which are controlled by a main script (Main.pl). Main Script Forks a process to run other scripts in different process and manages this process. While sending interrupt, i have written a interrupt handler in Main.pl. This handler prints "Wait I am killing". Now when I pass on an interrupt to my main program (while it is running another childs), this message is not printed once but many times (at-least the number of times the number of processes are running. Cannot understand why it is doing so.

Replies are listed 'Best First'.
Re: Interrupt Handling
by zentara (Archbishop) on Sep 02, 2012 at 10:16 UTC
    You havn't shown code, but it is likely you need a localized SIG handler in your children.
    #!/usr/bin/perl $SIG{INT} = sub { print "Caught zap in $$\n"; exit }; if ( my $pid = fork() ) { print "Parent Start\n"; sleep 5; local $SIG{INT} = sub { print "Parent $$ ignoring zap\n" }; kill 2 => $pid, $$; sleep 10; print "Parent exit!\n"; } else { print "Child start\n"; sleep 10; print "Child exit!\n"; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://991256]
Approved by Corion
help
Chatterbox?
[Dumu]: hello jedikaiti
[Dumu]: got it. Anyway. Perl question. Can you use binmode more than once with an open filehandle to read a file first in binary mode, then in utf8 mode?
[ambrus]: Dumu: you can use binmode multiple times, but mostly at the start before you read things. it would be strange to change the io layers after you've already read things, and might not work too well.
[ambrus]: Dumu: why would you want to read the same file both in binary mode and utf8 mode?
[Corion]: Dumu: Yes, but switching needs to be done with caution, as you might read half an UTF-8 character in binary mode, and then switch to utf8 mode...
[Corion]: Personally, I would do the decoding of data in the program and not in the filehandle
[Corion]: ambrus: Maybe a record-based file where some data is strings encoded as utf8

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2017-11-20 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (290 votes). Check out past polls.

    Notices?