Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-27-2013, 06:29 AM   #1
LQ Newbie
Registered: Jun 2013
Posts: 29

Rep: Reputation: Disabled
How to assign a bash shell program to many cpu core.

In my lab there are many computer and each computer has three cpu core.Now, I have a bash shell program file 'run'. I execute run like this.....
nohup ./run &

This program file use only one core and take long time to execute. how do I use all core for execution?

Can I use two or three computer for one program file execution?
Can I use 'taskset' or is there any other option?

Details of 'run'
for a in $a



Last edited by hoi; 06-27-2013 at 06:33 AM.
Old 06-27-2013, 08:39 AM   #2
Registered: Apr 2012
Location: Austin, TX
Posts: 44

Rep: Reputation: Disabled
You'll need to write a program to use the multiple cores; a simple bash script will not do this and I believe that is beyond the scope of this forum.

While - yes - you can use multiple computers for one program to run, you'll need to have a distributed processing setup; most likely, a cluster.
Old 06-30-2013, 09:41 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Pretty much as above....
If you write a single thread process, then it can only run on one core at a time (although the OS may move it to different cores over time).
If you want multi-processing (procs or threads), then you'll have to write code that works that way.
It can get tricky if the procs/threads have to talk to each other.
Old 06-30-2013, 10:12 PM   #4
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,241

Rep: Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407
Originally Posted by hoi View Post
Details of 'run'
Uh, does ./something.x actually use the parameter? Maybe more like
./something.x "$parameter"
. Anyway, assuming it's okay for multiple ./something.x runs to be executing at the same time:
a=(1 2)
for param in "${a[@]}" ; do
   ./something.x "$param" &
wait # block until all the somethings are finished.
If your script is actually that simple, you could just use xargs:
# A good value for max-procs is probably number-of-cpus
# but it depends on the details of ./something.x (does it do a lot of IO?)
echo 1 2 | xargs --max-args=1 --max-procs=3 ./something.x
xargs has the advantage that you can tune how many tasks to run in parallel, it's kind of tricky to pull that off in bash. The bash loop I posted above runs everything at once which may overwhelm the machine if you have a lot of tasks to run.

Last edited by ntubski; 06-30-2013 at 10:12 PM. Reason: grammar
Old 07-03-2013, 02:23 AM   #5
LQ Newbie
Registered: Jun 2013
Posts: 29

Original Poster
Rep: Reputation: Disabled
Thank you to all. Now I have got it and it is quite difficult to do.
Old 07-09-2013, 04:32 PM   #6
Registered: Sep 2006
Distribution: SuSE, Slackware
Posts: 55

Rep: Reputation: 4
Hey it might not be that difficult, take a look here:

elegant parallel processing in bash


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
bash shell program question rsatyandra Programming 10 07-24-2011 10:15 AM
Using Bash shell when I run a program from it jimmyrp Linux - Newbie 6 05-15-2011 01:54 PM
[SOLVED] Bash gurus: Using 'cut' to assign multiple shell variables? forbin Programming 9 08-08-2010 12:15 PM
How can you force a program/process to run on a specific CPU core? icedfusion Linux - Newbie 2 12-31-2008 11:10 AM
bash shell program help embsupafly Programming 7 11-27-2002 01:05 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:41 PM.

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