C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-14-2009, 12:02 PM   #1
Registered User
 
Join Date: Jan 2009
Posts: 159
How to parallel several jobs in bash

Hi,

I wonder how to in a bash script(or other languages if more convenient and/or fast) manage independent jobs(executables with command line arguments) and make them run in parallel? Is there a way to create several sub-process without waiting them to finish?

Which one is faster: multi-threading or multi-process?

Thanks and regards!
lehe is offline   Reply With Quote
Old 07-14-2009, 01:15 PM   #2
mastering the obvious
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,068
You can put a command into the background:

./myscript.sh &

This forks() and returns the command prompt right away *before* the script finishes, so you can start another one right away. You can put a string of these in a file:
Code:
#!/bin/bash

/home/user/bin/myscript1.sh &
/home/user/bin/myscript2.sh &
/home/user/bin/myscript3.sh &
and run that and all three will start almost simultaneously, ie, run in parallel.
__________________

“The essential element in the black art of obscurantism is not that it wants to darken individual understanding, but that it wants to blacken our picture of the world, and darken our idea of existence.” [Friedrich Wilhelm Nietzsche, 1878]
MK27 is offline   Reply With Quote
Old 07-14-2009, 01:43 PM   #3
Registered User
 
Join Date: Jan 2009
Posts: 159
Thanks!
is running background slower than foreground?
lehe is offline   Reply With Quote
Old 07-14-2009, 01:47 PM   #4
mastering the obvious
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,068
Quote:
Originally Posted by lehe View Post
Thanks!
is running background slower than foreground?
AFAIK there is no reason for it to be, depending on the console interaction and how the script is written it could be faster, but it should be the same generally.
__________________

“The essential element in the black art of obscurantism is not that it wants to darken individual understanding, but that it wants to blacken our picture of the world, and darken our idea of existence.” [Friedrich Wilhelm Nietzsche, 1878]
MK27 is offline   Reply With Quote
Old 07-15-2009, 03:08 PM   #5
Jaxom's & Imriel's Dad
 
Kennedy's Avatar
 
Join Date: Aug 2006
Location: Alabama
Posts: 863
The only issue would be a race condition for resources. If you have many processes fighting for the same disc, for example, then your overall performance will decline. Otherwise, each process will get a time slice for each task.
Kennedy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallel Port to USB controller and outb() coletek Linux Programming 1 06-05-2009 06:57 AM
argument with space passed to bash script and further to executable lehe Linux Programming 3 04-10-2009 12:57 AM
Open C/C++ Jobs for Top Developers Susan N Projects and Job Recruitment 7 06-04-2008 08:56 PM
Serial to Parallel ssharish2005 Tech Board 11 09-10-2007 01:11 PM
Segmentation Fault - Trying to access parallel port tvsinesperanto C Programming 3 05-24-2006 03:28 AM


All times are GMT -6. The time now is 04:08 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22