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 7736227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:41:36+00:00 2026-06-01T07:41:36+00:00

Perl script needs to receive ajax request, send a success message back to browser,

  • 0

Perl script needs to receive ajax request, send a “success” message back to browser, and then “spawn” a process to run in the background. (this spawned process could take 10 minutes to run, so I don’t want the browser to wait for that – or for an apache timeout to occur)

I was under the impression that the Perl exec() function would do this. Better than using fork() or system() since those are supposed to wait for a response.

But, the script seems to be waiting for the exec() program to finish before sending the success message to the browser. Here’s the very end of my Perl script:

print "Content-type: text/html\n\n";
print "success"; # this gets returned via ajax

exec $script_filename, $var1, $var2, $var3; 

Everything works, but the browser isn’t receiving the “success” message until $script_filename finishes running.

What I want to do seems similar to this previous post, but there aren’t enough specifics there.

Any ideas? Thanks.

  • 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-01T07:41:37+00:00Added an answer on June 1, 2026 at 7:41 am

    I found an answer to another StackOverflow question which seems to solve my problem – see Paul Tomblin’s response here.

    It seems that if the perl script does exec(), then apache waits. But if the perl script first does a fork, and then the fork does the exec(), then everything works as expected.

    And here’s what it looks like in my code, replacing what was in my original post:

    use POSIX 'setsid';
    
    $SIG{CHLD} = 'IGNORE';
    
    # This should flush stdout.
    my $ofh = select(STDOUT);$| = 1;select $ofh;
    
    my $kpid = fork;
    if ($kpid)
    {
        # Parent process
        print "Content-type: text/html\n\n";
        print "success"; # this gets returned via ajax
    }
    else
    {
        close STDIN;
        close STDOUT;
        close STDERR;
        setsid();
        my $gpid = fork;
        if (!$gpid)
        {
            open(STDIN, "</dev/null") ;
            open(STDOUT, ">/dev/null") ;
            open(STDERR, ">/dev/null") ;
            # Child process
            exec($script_filename, $var1, $var2, $var3) ;
        }
        exit 0;
    }
    

    Thanks to Adam for confirming right away that what I was originally trying to do was flawed.

    Thanks to Jonathan for pointing me in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a perl script that mimics gcc. This my script needs to process
Have a perl script that needs to process all files of a certain type
I have a Perl script that needs to run following an annual schedule with
I am working on a script that needs to run a perl script via
I've got a Perl script that needs to execute another Perl script. This second
I'm making a Perl script that needs to read and obtain the values of
I'm writing a shell script that before running needs to check that system Perl
I need a Perl script to spawn itself with an arbitrary name, i.e. so
I want to (need to) start a sub-process from a perl script that checks
I am writing a Perl script which needs to perform some validations. I have

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.