sub createDir { use 5.011; use Net::SFTP::Foreign; my ( $dirName, $sftp ) = @_; if ( $sftp->test_e($dirName) ) { if ( !$sftp->test_d($dirName) ) { print "Remove file(y/n)?: "; my $prompt1 = ; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { my $start = time; if ( fork() == 0 ) { # arm the alarm clock alarm(35); say "you got 35 seconds for process $$"; # create a child process my $return3 = $sftp->remove($dirName); say "return3 is remove file return: $return3"; createDir( $dirName, $sftp ); say "process $$ executed here"; exit(0); } system("pstree -Apal $$"); while ( ( my $pid = wait() ) != -1 ) { say "$pid terminated"; } say time - $start, " seconds elapsed instead of a year"; } #end if that tests !$sftp->test_d($dirName) next brace } if ( $sftp->test_d($dirName) ) { return "Directory $dirName already exists!"; } else { say "Can't create $dirName because there's a file in the way!"; handleDirCreateError( @_, $sftp->error() ); } } my $success = $sftp->mkdir($dirName) or handleDirCreateError( @_, $sftp->error() ); return $success; } sub handleDirCreateError { use 5.011; use Net::SFTP::Foreign; my ( $dirName, $sftp, $error ) = @_; say "parameter array is @_"; if ( fork() == 0 ) { # arm the alarm clock alarm(10); say "alarm set for ten in process $$ and pinging google"; # create a child process my $trial = system("ping www.google.com"); say "trial is $trial"; exit(0); } print "Bounce wireless(y/n)?: "; my $prompt1 = ; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { if ( fork() == 0 ) { # arm the alarm clock alarm(35); say "alarm set for 35 in process $$ and restarting network"; # create a child process my $trial2 = system("sudo service network-manager restart"); say "trial2 is $trial2"; sleep 30; say "sleeping 30"; exit(0); } } print "Do you think you're ready now(y/n)?: "; my $prompt2 = ; chomp $prompt2; if ( $prompt2 eq ( "y" | "Y" ) ) { my $return2 = createDir( $dirName, $sftp ); say "return2 is $return2"; } else { say "$error was too much this time: ceasing execution"; die; } return "execution shouldn't get here"; }