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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:56:34+00:00 2026-06-13T12:56:34+00:00

I’m trying to find or implement a simple solution that can sequentially queue up

  • 0

I’m trying to find or implement a simple solution that can sequentially queue up Linux shell commands, so that they are executed one at a time. Here are the criteria:

  1. The queue must execute the commands one at a time, i.e. no two commands can run at the same time.
  2. I don’t have the list of commands ahead of time. They will be coming in from web requests that my web server receives. That means the queue could be empty for a long time, and 10 requests can come in at the same time.
  3. My web server can only do system calls to the shell, so this program/solution needs to be callable from the command line.
  4. I only have one machine, so it can’t and doesn’t need to farm out the work to multiple machines.

Originally I thought the at command can do what I want, but the only thing is that it doesn’t execute the commands sequentially.

I’m thinking of implementing my own solution in python with these parts:

  1. Have a dedicated directory with a lock file
  2. Queued commands are stored as individual files with the filename containing an incrementing sequence ID or timestamp or something similar, which I’ll call “command files”
  3. Write a python script using fcntl module on the lock file to ensure only 1 instance of the script is running
  4. The script will watch the directory for any files and execute the shell commands in the files in the order of the filename
  5. When the directory has no more “command files”, the script will unlock the lock file and exit
  6. When my web server wants to enqueue jobs, it will add a new “command file” and call my python script
  7. The python script will check if another instance of itself is running. If yes, then exit, which will let the other instance handle the newly queued “command file”. If no, then lock the lock file and start executing the “command files” in order

Does this sound like it’ll work? The only race condition that I don’t know how to handle is when the first instance of the script checks the directory and see that it’s empty, and before it unlocks the lock file, a new command is queued and new instance of the script invoked. And that new script will exit when it sees the file is locked. Then the original script will unlock the file and exit.

Is there something out there that already do this, so I don’t have to implement this myself?

  • 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-13T12:56:35+00:00Added an answer on June 13, 2026 at 12:56 pm

    Use a named pipe, aka FIFO:

    mkfifo /tmp/shellpipe
    

    Start a shell process whose input comes from the pipe:

    /bin/sh < /tmp/shellpipe
    

    When the web server wants to execute a command, it writes it to the pipe.

    sprintf(cmdbuf, "echo '%s' > /tmp/shellpipe", command);
    system(cmdbuf);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.