tags:

views:

312

answers:

5

I am trying to write a .sh file that runs many programs simultaneously

I tried this

prog1 
prog2

But that runs prog1 then waits until prog1 ends and then starts prog2...

So how can I run them in parallel?

Thanks

+8  A: 
prog1 &
prog2 &
psmears
Do not forget the `wait`! Yes, in bash you can wait for the script's child processes.
Dummy00001
Another option is to use `nohup` to prevent the program from being killed when the shell hangs up.
Philipp
+3  A: 
#!/bin/bash
prog1 & 2> .errorprog1.log; prog2 & 2> .errorprog2.log

Redirect errors in separate log's

fermin
Dennis Williamson
the semicolon execute both comands, you can test de bash to see it work well ;)Example: pwd
fermin
A: 

There is a very useful program that calls nohup.

     nohup - run a command immune to hangups, with output to a non-tty
ochach
+1  A: 

You can try ppss. ppss is rather powerful - you can even create a mini-cluster. xargs -P can also be useful if you've got a batch of embarrassingly parallel processing to do.

ljt
A: 

With GNU Parallel http://www.gnu.org/software/parallel/ it is as easy as:

(echo prog1; echo prog2) | parallel
Ole Tange