Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Bash process co-ordination

Posted on 2011-03-02
8
Medium Priority
?
335 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 31

Author Comment

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

$Command3
$Command4
0
 
LVL 12

Assisted Solution

by:mccracky
mccracky earned 400 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 1600 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

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…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

885 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