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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:38:43+00:00 2026-05-14T06:38:43+00:00

I have a perl cgi script that’s fairly resource intensive (takes about 2 seconds

  • 0

I have a perl cgi script that’s fairly resource intensive (takes about 2 seconds to finish). This is fine as long as only at most 4 or 5 of them are running at the same time and that’s usually the case.

The problem is that when a user clicks a link that calls this script, a new process is spawned to handle that connection request, so if a user clicks many times (if they’re impatient), the server gets overloaded with new processes running and most of them are redundant.

How can I ensure that only one instance of this process is running per host?

This is an old system that I’m maintaining which uses an old framework for the frontend, and I would like to avoid using javascript to disable the button client side if possible. Converting this to fast-cgi perl is out of the question as well, again because this is an old system and adding fast-cgi to apache might break a lot of other things that this thing runs.

  • 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-05-14T06:38:43+00:00Added an answer on May 14, 2026 at 6:38 am

    You want to use a file lock. Read the documentation on the Fcntl module and the flock function: http://perldoc.perl.org/functions/flock.html

    Edit in response to comment:

    Example of using a lock file:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use Fcntl qw(:flock);
    
    local *FH;
    my $opened_file = open(FH,'>/tmp/example_file.lck');
    if ($opened_file) {
        print "Lock file was opened successfully\n";
        if (flock(FH, &LOCK_EX | &LOCK_NB)) {
            &do_stuff();
        } else {
            print "Failed to get lock (another process is running)\n";
        }   
    } else {
        print "Failed to open lock file: $!\n";
    }
    close(FH);
    
    sub do_stuff {
        print "Locked!\n";
        sleep 30; # Pretending to be busy for a long time
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 505k
  • Answers 505k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A combination of adding /platform:x86 to the pcy.py call and… May 16, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer If you are using 2.3.x, I've always found Searchlogic to… May 16, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer See answer by Pascal Bourguignon. May 16, 2026 at 3:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a Perl CGI script that creates a login screen, i.e. user name
I have a Perl CGI script that isn't working and I don't know how
I have a Perl CGI script that emits different HTML apparently randomly. None of
I have a script that's written in perl, and executed as CGI. It works
What should you call after printing HTML from a Perl CGI script? I have
I have a perl script (Cgi / Apache / Windows) which executes some programs
I have a need to upgrade a Perl CGI script where the users must
I have the following, simplest Perl CGI script: use strict; use warnings; use CGI();
i have a perl script that is used in updating my awstats logs of
I have a perl CGI that needs to report some information back to the

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.