LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-18-2010, 11:02 AM   #16
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 184

Original Poster
Rep: Reputation: 28

Quote:
Originally Posted by primerib View Post
Here's a breakdown:
Code:
until [ "$DONE1" ] && [ "$DONE2" ]; do                            # loop until $DONE1 and $DONE2 exist (ie: until both processes return)
    if [ check for process1 return ] && [ ! "$DONE1" ]; then      # check if process1 has returned && if we should do this check
        if [ process1 error ]; then do kill process2; exit 1; fi  # process1 returned, did it have an error? if yes, kill process2 and exit script
        DONE1=1                                                   # process1 returned without error, set DONE1 flag to tell the script we don't need
                                                                  # to check this anymore
    elif [ check for process2 return ] && [ ! "$DONE2" ]; then    # check ifprocess2 has returned && we should do this check
        if [ process2 error ]; then do kill process1; exit 1; fi  # process2 returned, did it have an error?  if yes, kill process1 and exit script
        DONE2=1                                                   # process2 returned without error, set DONE2 flag to tell the script we don't need
                                                                  # to check this anymore
    fi
done                                                              # if DONE1 is set && DONE2 is set, both processes returned without error and we are finished with the check
So setting DONE1 and DONE2 to a value just says the process returned without error.
Wouldn't the first line be:
Code:
until [ "$DONE1" ] || [ "$DONE2" ]; do
If I use && and "wait for both processes to exit" then there would be no point in killing process2 if process1 exits with an error since both processes have already exited. I mean it would work to wait for both processes to exit, but I am trying to save some time by killing the other process if one exits with an error. The reason is because each process take about an hour to run, and if one process exits with an error it invalidates my test, so I don't want to wait for an hour when both processes have to just be ran again.

Last edited by dbrazeau; 03-18-2010 at 11:03 AM.
 
Old 03-18-2010, 12:33 PM   #17
primerib
Member
 
Registered: Mar 2010
Posts: 48

Rep: Reputation: 20
Quote:
Originally Posted by dbrazeau View Post
Wouldn't the first line be:
Code:
until [ "$DONE1" ] || [ "$DONE2" ]; do
If I use && and "wait for both processes to exit" then there would be no point in killing process2 if process1 exits with an error since both processes have already exited. I mean it would work to wait for both processes to exit, but I am trying to save some time by killing the other process if one exits with an error. The reason is because each process take about an hour to run, and if one process exits with an error it invalidates my test, so I don't want to wait for an hour when both processes have to just be ran again.
What happens if one process ends without error and the other one is still running? Don't you want to know if both processes end without error? Using || will stop the wait loop if either process ends (without error), and ignore what's happening with the other process. Using && only stops the loop if one end with error, or both end clean.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make shell script wait for a particular key pressed in order to proceed? Caed Lucin Linux - General 5 01-31-2010 06:08 PM
How to make shell script wait for key press to proceed... ddenton Linux - General 13 12-02-2008 04:25 AM
Wait for one of two processes to complete in a shell script nonoitall Programming 11 06-10-2008 04:10 PM
can you do threading or multiple processes in a shell script? BrianK Programming 8 08-07-2006 04:40 PM
Shell-Script for killing processes oulevon Programming 4 02-14-2006 10:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration