LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using 'time' command with multiple background processes (https://www.linuxquestions.org/questions/linux-newbie-8/using-time-command-with-multiple-background-processes-668506/)

jiffydude 09-08-2008 08:23 PM

Using 'time' command with multiple background processes
 
To test various compiler optimizations, I'm running a shell script which runs several processes in the background simultaneously:

Code:

./readfile output1.clock.bin filter1.bin &
./readfile output2.clock.bin filter2.bin &
./readfile output3.clock.bin filter3.bin &
./readfile output4.clock.bin filter4.bin &

When I try to use the bash 'time' builtin or the GNU 'time' command, it seems as though the command will only time the execution of the script itself, which is not helpful (that takes about 0.00s!).

I've tried various combinations of parentheses, &'s, &&'s, etc. but I can't seem to find the right syntax...

I would like to be able to run N processes, in the background, simultaneously, in order to test the processing capabilities of my CPU.

Thanks in advance!

-Jordan

klearview 09-08-2008 09:09 PM

Can you not just take the contents of your script and use them as actual command?

chrism01 09-08-2008 09:43 PM

Add the cmd 'time' to the start of each cmd line and save the output to a numbered file

jiffydude 09-08-2008 10:48 PM

@chrism01,

Do you mean to make a separate output file for each command, and then to add up the times by hand? Take the average of the times?

I would like to know how long it takes to run all 4 commands, simultaneously. Call it a simple experiment in parallel processing.

I was looking for something like this:

Code:

time ( command1 & ; command2 & ; command3 & )
but this doesn't execute the commands simultaneously. A pipe does, so I read, but these commands are not related, so can't be sensibly piped.

Mr. C. 09-08-2008 10:57 PM

Use wait:

Code:

$ cat sleep.sh
#!/bin/bash

sleep 2 &
sleep 10 &
sleep 5 &
wait

$ time ./sleep.sh

real    0m10.017s
user    0m0.734s
sys    0m0.729s


jiffydude 09-09-2008 08:16 PM

@Mr. C: That's exactly what I needed. Thanks.


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