Visit Jeremy's Blog.
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-08-2010, 01:32 AM   #1
Registered: Feb 2007
Posts: 386

Rep: Reputation: 30
script to sync producer consumer application.

I have a producer and consumer application, each can take parameter
and run for 10 minutes.

I want to write a script that allow me to pass in different paramters
and save the results for later. However, I cannot come up with a write

Can someone suggest a good approach or any tool that can help?

My scenario is that the consumer has to start first always.
Once the first set of parameter finish. the producer will not start
until the consumer for the next parameter set starts
I am thinking something like this


for ($i=1;$i<10;$i++) -interval $i
sleep 1

for ($i=1;$i<10;$i++) -interval $i
# wait till consumer is done
sleep 1;

I am trying to go with an approach that checking if the consumer/producer finish by checking a log file, but it does not seem to work.
Maybe someone has done something similar already
Old 06-08-2010, 01:51 AM   #2
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
One approach to check for running apps would be to use "PID files" in /var/run, like daemons do. In these files, the daemon logs it's process ID (PID) number when it starts up (and clears/removes the file when it finishes).

My scenario is that the consumer has to start first always.
Once the first set of parameter finish. the producer will not start
until the consumer for the next parameter set starts
After reading your scenario, though, I'm not sure that it's a daemon like approach that you want.
How about this approach:

Code:; #run once, wait for consumer to finish - first consumer
for ($i=1;$i<10;$i++); do &; #no need to wait; #wait till completed
In the first iteration, the producer will start just after the first consumer finished.
A sleep time between producer & consumer can help make sure that the producer is done roughly by the
time that the repeated consumer is done as well.

A while-loop can be more suitable for this.
Old 06-08-2010, 09:55 AM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Your problem is that of synchronization. In your script, you have the comment '# wait till consumer is done'. How will your producer process know that the consumer is done? And the flip-side question is, how does the producer know that a new consumer process is ready? Once you've answered these questions, I think you will have the solution.
--- rod.


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
Application time does not sync with the server SBN Linux - General 3 03-21-2009 10:09 AM
How to implement a POSIX threaded program to solve producer/consumer problem cy163 Programming 3 09-13-2008 09:38 AM
Producer & Consumer issue with php on mysql ufmale Programming 3 03-13-2008 02:08 AM
LXer: Tapping Linux as an application framework for consumer electronics LXer Syndicated Linux News 0 10-26-2006 05:54 PM
The old producer-consumer problem still a problem for me!!!!!!!!!!!!! skie_knite007 Programming 1 12-14-2005 07:39 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:05 PM.

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