How do I time a compound command when most but not all commands executed in parallel:

For example the command:

comd1 ; comd2 & comd3 & comd4 & comd5 &

I tried

time (comd1…)

But from the output I can speculate that only comd1 was timed because comd2 to comd5 usually are not so fast to finish executing when being executed alone.


You could add a wait to wait for all background processes.


$ time (sleep 1; sleep 2 & sleep 4 & wait)
real    0m5.007s
user    0m0.004s
sys     0m0.005s

$ time (sleep 1; sleep 6 & sleep 4 & wait)
real    0m7.011s
user    0m0.005s
sys     0m0.003s

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.