On Feb 15, 12:35 pm, shawnhco...@gmail.com (Shawn H Corey) wrote: > Matthias Meyer wrote: > > Hi group, > > > I try to catch a signal, write out some statistics about my running > > perl program and continue afterwards with the program. > > > use strict; > > no utf8; > > use MyProgram::Lib; > > use Encode; > > use Socket; > > use File::Path; > > use File::Find; > > use Getopt::Std; > > die("MyProgram::Lib->new failed\n") if ( !(my $init = MyProgram::Lib->init) > > ); > > $SIG{ILL} = \&write_status; > > : > > sub write_status > > { > > my $sigName = shift; > > > print( STDERR "Signal ILL catched" ); > > return; > > } > > Within bash I send the signal with "kill -4 <procID>" > > Unfortunately my program die after catching the signal. > > Without the print it dies too. > > Also within debugger (perl -d:ptkdb) it dies after the return statement. > > > Is it possible to interrupt a perl program and continue afterwards? > > > Thanks > > Matthias > > What OS? > > Normally a program continues but if it is waiting or sleeping, it > continues after the command. You have to redo the command until it > terminates correctly. Example: waiting for a child process: > > my $child_pid = 0; > WAIT_BLOCK: { > $child_pid = wait(); > redo WAIT_BLOCK if $child_pid == 0 || $child_pid < -1; > > } >
No, you don't need 'redo' on a blocking wait. I see why you might conclude that reading the waitpid doc but I believe the that doc is mis-leading in not clarifying that only a non-blocking wait, ie, WNOHANG, will potentially return a 0. See: http://groups.google.de/group/perl.beginners/browse_thread/thread/71ac675f384a9828 Here're the key parts of that exchange which may look remarkably familiar :) > On some systems, a value of 0 indicates that there are processes still > running. >> I see that but I suspect Perl's waitpid doc is unintentionally >> misleading. >> A quick look at Linux and OpenBSD wait(2) manpages specifies a 0 >> return can occur only with FLAGS set to WNOHANG. >> OpenBSD: from waitpid(2) manpage: >> Otherwise, if WNOHANG is specified and there >> are no stopped or exited children, 0 is returned. >> Linux: >> ... if WNOHANG was specified and no child(ren) specified by pid >> has yet changed state, then 0 is returned. > In other words, waitpid can return a value which is not the pid of the > child you requested. Therefore redo, since it's a foreach loop. This, > of course, is only true on some systems; it may not be true on yours. >> If there's a system where a blocking waitpid could return something >> other than -1 or the specific pid you waited on, that'd be true. But, >> even then, you'd have to be careful that a -1 indicating a reaped >> process didn't cause an endless loop due to the 'redo'. -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/