All of lore.kernel.org
 help / color / mirror / Atom feed
* Keeping all CPUs busy
@ 2003-08-13 19:17 Urs Thuermann
  2003-08-13 19:42 ` Jeff Woods
  0 siblings, 1 reply; 2+ messages in thread
From: Urs Thuermann @ 2003-08-13 19:17 UTC (permalink / raw)
  To: linux-smp

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.


urs

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Keeping all CPUs busy
  2003-08-13 19:17 Keeping all CPUs busy Urs Thuermann
@ 2003-08-13 19:42 ` Jeff Woods
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Woods @ 2003-08-13 19:42 UTC (permalink / raw)
  To: Urs Thuermann; +Cc: linux-smp

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> 



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-08-13 19:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-13 19:17 Keeping all CPUs busy Urs Thuermann
2003-08-13 19:42 ` Jeff Woods

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.