Solved

Bash process co-ordination

Posted on 2011-03-02
8
333 Views
Last Modified: 2012-08-13
My script runs four commands.  $Command1 and $Command2 should run in parallel as background processes.  $Command3 cannot run unless both the first and second have completed.  How should I enforce this?  Please tell as many solutions/options.  Any IPC (inter process communication)?
0
Comment
Question by:farzanj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 12

Expert Comment

by:mccracky
ID: 35024077
A simple way would be to write pid or lock files for command1 and command2 and clear them when done.  Command3 waits for those pid/lock files to be cleared before starting up.
0
 
LVL 31

Author Comment

by:farzanj
ID: 35024084
Please show the code.  I need step by step help, please.
0
 
LVL 12

Expert Comment

by:mccracky
ID: 35024098
Show us what you already have in your script, please.  Then we can help you.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Author Comment

by:farzanj
ID: 35024118
$Command1 &
$Command2 &

$Command3
$Command4
0
 
LVL 12

Assisted Solution

by:mccracky
mccracky earned 100 total points
ID: 35024205
Right off the top of my head and quick and dirty:
You might need to wrap command1 and command2 in a script that clears the lock file something like

command1.sh:

#!/bin/bash
touch /tmp/command1.lock
command1
rm /tmp/command1.lock


main script steps:

1. command1.sh &
2. command2.sh &
3. loop testing if /tmp/command1.lock and /tmp/command2.lock are there
4. command3
5. command4
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 400 total points
ID: 35024490
try this under bash

command1 &
pid1=$!
command2 &
pid2=$!
 wait $pid1 $pid2
command3

here the wait command will wait till both command1 and command2 processes are over, then process3 will run
0
 
LVL 31

Author Closing Comment

by:farzanj
ID: 35026455
Thanks for your help.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 35030545
welcome
0

Featured Post

Stack Overflow Podcast - Frustrating Miracles

In this podcast, Stack Overflow interviewed Linux Academy CEO/Founder, Anthony James, and got his developer story!

"Follow your passion, be prepared to work hard and sacrifice, and, above all, don't let anyone limit your dreams."  - Donovan Bailey

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question