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

  • Home
  • SEARCH
  • 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 105001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:22:13+00:00 2026-05-11T01:22:13+00:00

There are several ways to do this, but I’m not sure which one of

  • 0

There are several ways to do this, but I’m not sure which one of them is the best.

Here’s what I can think of:

  • Look for the process using pgrep.
  • Have the script lock itself using flock, and then check if it is locked each time it runs.
  • Create a pid file in /var/run/program_name.pid and check for existence, and compare pids if needed.

There are probably more ways to do this. What do you think is the best approach?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T01:22:13+00:00Added an answer on May 11, 2026 at 1:22 am

    There are many ways to do it. PID files are the traditional way to do it. You could also hold a lock on a file, for example the program itself. This small piece of code will do the trick:

    use Fcntl ':flock'; open my $self, '<', $0 or die 'Couldn't open self: $!'; flock $self, LOCK_EX | LOCK_NB or die 'This script is already running'; 

    One advantage over PID files is that files automatically get unlocked when the program exits. It’s much easier to implement in a reliable way.

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

Sidebar

Related Questions

There are several questions discussing ways in which progress indication can be added to
In Org-mode there are several ways to make comments . But I do not
There are several different ways I can initialize complex objects (with injected dependencies and
I already have several ways to solve this, but I am interested in whether
I tried several ways but it seems I'm missing something.. Here is the code
I know there are several ways to do it, but I would like to
I know this has been asked before in several ways but none of the
There are several ways to iterate over a result set. What are the tradeoff
I understand that there are several ways to blend XNA and WPF within the
I know there are several ways to deploy a .net windows client application: There's

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.