Solved

Bash process co-ordination

Posted on 2011-03-02
8
327 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
  • 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
 
LVL 31

Author Comment

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

$Command3
$Command4
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now