LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 09-08-2008, 09:23 PM   #1
jiffydude
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:

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
 
Old 09-08-2008, 10:09 PM   #2
klearview
Member
 
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
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
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
jiffydude
LQ Newbie
 
Registered: Sep 2003
Posts: 5

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

Rep: Reputation: 61
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
 
Old 09-09-2008, 09:16 PM   #6
jiffydude
LQ Newbie
 
Registered: Sep 2003
Posts: 5

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


Reply


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


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

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