Bash process co-ordination

Posted on 2011-03-02
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)?
Question by:farzanj
  • 3
  • 3
  • 2
LVL 12

Expert Comment

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.
LVL 31

Author Comment

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

Expert Comment

ID: 35024098
Show us what you already have in your script, please.  Then we can help you.
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

LVL 31

Author Comment

ID: 35024118
$Command1 &
$Command2 &

LVL 12

Assisted Solution

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

touch /tmp/command1.lock
rm /tmp/command1.lock

main script steps:

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

Accepted Solution

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

command1 &
command2 &
 wait $pid1 $pid2

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

Author Closing Comment

ID: 35026455
Thanks for your help.
LVL 40

Expert Comment

ID: 35030545

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ubuntu not booting - How get past GRUB? 3 43
Linux Ubuntu - Volume "boot" has only 0 bytes disk space remainig 6 57
powershell function location 6 39
linux 13 49
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…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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.:

776 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