Hi! So here I sit, befuddled with this little chunk of code. Consider it a learning experience in signals since I could prolly just find something in CPAN that is more robust.. but have yet to, to understand my faux pas.

I'm trying to maintain multiple virtual scp's of sorts. This allows for some neat administration tricks, when I need the logfile here, but it's somewhere else. This is the bare-bone version, without the continuing where I left off in terms of the last line retrieved. I know how to do that :)

I can start it up, kill a child process directly, and a new one will take its place. I can kill the shell process started by system (note, system() used to be exec(), but I flipflopped trying to get it to work), and have a new process start up. Problem is, if i do a kill -HUP of the main process, it kills the other perl processes fine, but not the processes started by system/exec. Hepl! (a cookie to those who get the hepl reference)

use strict; #Because `system' and backticks block `SIGINT' and #SIGQUIT', killing the program they're running #doesn't actually interrupt your program. $SIG{HUP} = \&shutdown; $SIG{CHLD} = 'IGNORE'; my %PIDPOOL = (); my $continue = 1; for( my $x = 1; $x < 3; $x++) { setupProcess( $x ); } while( $continue ) { my $pid = wait(); if( $pid > 0 ) { my $process = $PIDPOOL{ $pid }; print "Process $process destroyed...\n"; setupProcess( $process ); } } sub shutdown( ) { $continue = 0; foreach my $pid ( keys %PIDPOOL ) { kill "HUP", $pid; } print "Shutting down...\n"; while( ( my $pid = wait() ) != -1 ) { print "$pid killed on shutdown of parent process...\n" +; } } sub setupProcess( ) { my $process = shift; my $pid = fork(); if( $pid ) { $PIDPOOL{ $pid } = $process; } else { $SIG{HUP} = sub{ print "Killing ssh...\n"; kill "ABRT +", -$$; }; print "$process started...\n"; # replaceable with exec( ) or die(...) system( "/bin/sh -c 'ssh sporty\@tao \"tail -f t\" > +t$process'") or die($!); exit; } }

In reply to Signals and subprocesses using fork, and system or exec. by exussum0

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.