Return code for parallel running threads

Hi,

How to use the return code, for parallel running threads.

Ex-

grep pattern1 file1 file2 file3 file4 &
grep pattern1 file5 file6 file7 file8 &
grep pattern1 file9 file10 file11 file12 &

return_code=$?
if (return_code -eq 0)
then
echo "pattern found"
else
echo "pattern not found"
fi

Here, in this above samples of code, how to use return codes effectively, for the concurrent running greps, so that, i can get correct result for, "pattern1" is found in which grep.

It seems that, I need to use the thread locking and unlocking principle here. However, i am a bit confused, how to use this concept over here.

Please help.

Please indicate, if you need any further clarification of the problem.

Thanks and Regards,

Jitendriya Dash.

You really cannot. You can get the return code for the most-recently launched and most-recently exited. What I don't understand, however, is that when you provide grep with more than one file name, it will print out the filename for each matching line. Why can't you rely on this feature?

grep pattern1 file[1-12] &