[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-smp
Subject:    Re: Keeping all CPUs busy
From:       Jeff Woods <kazrak+kernel () cesmail ! net>
Date:       2003-08-13 19:42:29
[Download RAW message or body]

At +0200 09:17 PM 8/13/2003, Urs Thuermann wrote:
>I sometimes run many CPU-intensive processes in a loop like this
>
>     for f in *; do lame -h $f ${f/wav/mp3}; done
>
>However, this will run only one process at a time.  Executing all
>processes in the background would execute them all at the same time.
>Is there an easy way to run n processes at time, when you have n CPUs?
>
>On could of course write an Makefile and run make -j2, but I'd like to
>know I there is a simpler way without Makefile or something like that.

         for f in *; do lame -h $f ${f/wav/mp3} &; done; wait

That starts them all in the background.  I wouldn't normally do that if the 
number of files is large and the total work done is nontrivial.

The "wait" command tells bash to wait for all the background processes to 
complete.  Without it, you get the shell prompt back immediately (which may 
be what you want).

If you're working on a shared system, you should think twice about grabbing 
so many resources at once, and if you still decide to do it you should do 
"... do nice lame ..." or something similar to run them at a lower priority 
so that other interactive users (including you) get first shot at the CPU.

--
Jeff Woods <kazrak+kernel@cesmail.net> 


-
To unsubscribe from this list: send the line "unsubscribe linux-smp" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic