Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-08-2008, 09:23 PM   #1
LQ Newbie
Registered: Sep 2003
Posts: 5

Rep: Reputation: 0
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:

./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!

Old 09-08-2008, 10:09 PM   #2
Registered: Aug 2006
Location: London
Distribution: Debian, Kubuntu
Posts: 572

Rep: Reputation: 75
Can you not just take the contents of your script and use them as actual command?
Old 09-08-2008, 10:43 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,818

Rep: Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558
Add the cmd 'time' to the start of each cmd line and save the output to a numbered file
Old 09-08-2008, 11:48 PM   #4
LQ Newbie
Registered: Sep 2003
Posts: 5

Original Poster
Rep: Reputation: 0

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:

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.
Old 09-08-2008, 11:57 PM   #5
Mr. C.
Senior Member
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Use wait:

$ cat 

sleep 2 &
sleep 10 &
sleep 5 &

$ time ./

real    0m10.017s
user    0m0.734s
sys     0m0.729s
Old 09-09-2008, 09:16 PM   #6
LQ Newbie
Registered: Sep 2003
Posts: 5

Original Poster
Rep: Reputation: 0
@Mr. C: That's exactly what I needed. Thanks.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Scripting and background processes PatrickNew Programming 5 03-04-2008 11:56 PM
ps command displays multiple processes mghiya Linux - Software 0 07-28-2006 05:28 AM
background processes digit Linux - Software 3 07-27-2003 01:27 PM
processes in background zetsui Linux - General 8 06-14-2003 01:52 PM
background processes hakum Programming 1 04-08-2002 11:29 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:35 AM.

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