Solved

Bash process co-ordination

Posted on 2011-03-02
8
331 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
Industry Leaders: 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
list of sudo access for date range 5 37
Renaming with batch file 9 106
Can't connect to FTP 18 148
Linux kernel panic ext3-fs error 14 67
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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