LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: 15
Queuing same processes


Hello.

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.
Regards.
 
Old 06-15-2009, 08:17 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
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, 05:07 PM   #3
RVF16
Member
 
Registered: May 2008
Distribution: Centos 5.9
Posts: 53

Original Poster
Rep: Reputation: 15
Solved

Thank you.
flock did the trick.

Regards.

PS:
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 03:38 AM.
 
  


Reply


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 11:54 AM
Linux PC router messes up fair queuing pcweirdo Linux - Networking 1 08-02-2007 04:28 AM
Queuing a BDR SCB jspsandhu *BSD 0 02-28-2006 03:48 PM
Sound queuing mewt Mandriva 8 05-09-2005 09:46 AM
How to implement a queuing system? aleet2600 Programming 10 05-13-2004 12:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:03 AM.

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