Solved

Bash process co-ordination

Posted on 2011-03-02
8
326 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

760 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

22 Experts available now in Live!

Get 1:1 Help Now