Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-15-2009, 05:38 AM   #1
Registered: May 2008
Distribution: Centos 5.9
Posts: 53

Rep: Reputation: 15
Queuing same processes


I have a bash script "usbtv" that can be called from other scripts multiple times simultaneously.
Problem is that due to the nature of the processes it runs, it must be run only once at a time.
Is there a good way to make the usbtvs queue themselves so that each can wait until the running one is finished and then commence?

I thought of making them export their pids to a text file and calculating priorities but what if more than one "usbtv" try to access and edit that file at the same time?

Thank you.
Old 06-15-2009, 07:17 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,530

Rep: Reputation: 110Reputation: 110
You can use the shell-util "flock" for that.
You can use "flock" to make sure other script processes will wait until one is done. It won't do priorities and/or queueing, the waiting script that happens to wake up first gets the new lock.

See "man 1 flock" for more info.
Old 06-15-2009, 04:07 PM   #3
Registered: May 2008
Distribution: Centos 5.9
Posts: 53

Original Poster
Rep: Reputation: 15

Thank you.
flock did the trick.


I used the parenthesis structure

( flock -x 200
code that needs to be run once a time
) 200>/path/to/lock

as i needed to run several commands in a raw without loosing the lock.
This parenthesis part acts as a child (script) which means that inside it you can utilize the main script variables (parent script) but any changes you make to them will not be passed to the main script so you will have to e.g. write them in a text file before closing the parenthesis and reread them from that text file after you close the parenthesis.

Last edited by RVF16; 06-16-2009 at 02:38 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
KGet: queuing downloads not working? nfisk Linux - Desktop 2 02-08-2008 10:54 AM
Linux PC router messes up fair queuing pcweirdo Linux - Networking 1 08-02-2007 03:28 AM
Queuing a BDR SCB jspsandhu *BSD 0 02-28-2006 02:48 PM
Sound queuing mewt Mandriva 8 05-09-2005 08:46 AM
How to implement a queuing system? aleet2600 Programming 10 05-12-2004 11:03 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration