Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:33:29+00:00 2026-06-13T08:33:29+00:00

I have a simple perl script that calls a shell script which always hangs

  • 0

I have a simple perl script that calls a shell script which always “hangs” when called from the browser. I want to simply force a time out after 20 seconds. When I run it in command line there is no issues. But when I do it from the browser, the script is executed but never finishes loading. So I don’t get the output on the page. If I kill -9 the process in the command line, the browser finishes loading, and the content is displayed in the browser.

I did a lot of research, and it seems the web server is waiting for the shell script to finish, because the shell script still has an open file handle to the standard output.

Here is my code.

#!/usr/bin/perl

use strict;
use warnings;

use CGI;

my $q = new CGI;

print $q->header;

my $timeout = 10;
my $pid = fork;

if ( defined $pid ) {
     if ( $pid ) {

         # this is the parent process
         local $SIG{ALRM} = sub { die "TIMEOUT" };

         alarm 10;

         # wait until child returns or timeout occurs    
         eval {
             waitpid( $pid, 0 );
         };

         alarm 0;

         if ( $@ && $@ =~ m/TIMEOUT/ ) {
            # timeout, kill the child process
            kill 9, $pid;
         }
    }
    else {
         # this is the child process
         # this call will never return. Note the use of exec instead of system
         exec "/opt/bea/domains/fsa/scripts/start.sh";
    }
}
else {
     die "Could not fork.";
}

How do I force the page to finish loading regardless of the status of the shell script after a certain amount of time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:33:29+00:00Added an answer on June 13, 2026 at 8:33 am

    Problem is that after your script finishes, webserver is still waiting for all child created (even created by you) to finish. Best way how to handle it is to create separate process group with setsid. Or you can even try the “double fork trick“, where you fork and from child then fork again. After that the first child will exit and the second child becomes child if init. Also make sure that (in both cases) in child you do:

    close STDIN;
    close STDOUT;
    close STDERR;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to source a shell script from within Perl and have the environment
I have a simple Perl script that simply prints a line of text to
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
I have a simple Perl script which runs as a Linux daemon using an
I have a quite simple perl script, that in one function does the following:
I have a very simple perl script that moves files (don't ask why i
I want to write a script foo which simply calls bar with the exact
I have a simple Perl script that prints out @INC as the following: #!/usr/bin/perl
I have a simple perl script that uses DBD::Oracle to run a query and
I have a Perl script that reads a simple .csv file like below- header1,header2,header3,header4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.