0

I'm using a korn shell. Is this a possible scenario using wait? Where I have (2) instances of it?

#!/usr/bin/ksh
a &
wait
b &
c &
wait
d

My goal is to run a first, once complete, then fire off b,c at the same time. Once b,c is complete, then run "d".

Wooble
  • 87,717
  • 12
  • 108
  • 131
jdamae
  • 3,839
  • 16
  • 58
  • 78

1 Answers1

2

I'm not sure I fully understand the semantics of your situation.
It seems to me that the problem that you are facing revolves around waiting for both b and c.

Here is how this can be solved (potentially)
First you wait on a..the moment the wait returns, you fire b and c. You can use two waits - one for b and one for c..the order of these does not matter since you want to wait on both anyway.
Once both waits have returned, you can fire d.

  • Fire a
  • Wait a
  • Fire b,c
    • Fire b
    • Fire c
  • Wait b,c
    • Wait b
    • Wait c
  • Fire d
Guru Prasad
  • 4,053
  • 2
  • 25
  • 43
  • It depends on whether you want A to run in the background or not..that is entirely up to you. As for B and C, since you want them to run in parallel, you will have to run these in the background. The order of the waits doesn't matter in this case since you want both to complete before executing your next statement – Guru Prasad Aug 13 '13 at 15:19
  • Is there an additional way to check for b,c to complete before moving on to fire d? – jdamae Aug 13 '13 at 15:26
  • do you mean simultaneously check? I don't think so..Take a look at http://stackoverflow.com/a/356154/1761555 for some additional details – Guru Prasad Aug 13 '13 at 15:42
  • you could obtain the PID's of b and c and check whether they've quit (or are still running) – Guru Prasad Aug 13 '13 at 17:22
  • Could you please mark this as correct if it worked for you? Others might find it useful as well. – Guru Prasad Aug 15 '13 at 01:44