Bash script multithread in group of 3


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script multithread in group of 3
# 1  
Old 05-31-2010
Bash script multithread in group of 3

I Have an script like


./bang 1
./bang 2
./bang 3
./bang 4
./bang 5
./bang 6
./bang 7
./bang 8
./bang 9
./bang 10
./bang 11
./bang 12


and i wanna execute him in groups of 3 , i mean he execute bang 1 , bang 2 and bang 3 after it finish the next 3 commands it will be executed and so on , in groups of 3.


Regards
John Hardey
# 2  
Old 06-01-2010
Do you mean to say executing each set of three simultaneously ? ( background) and wait for them to finish before executing next three?
if not so, they are anyway will be executed one by one. no matters set of three!!!

for first case, you can try something like,

Code:
#!/usr/bin/ksh

i=1
while [ $i -le 12 ]
do
 ./bang $i &
 ./bang $(( i+1 )) &
 ./bang $(( i+2 )) &
 wait 
 i=$(( i+3 ))
done

# 3  
Old 06-01-2010
It is faster in set of three or lets say ten

I mean in set of three it will be faster or in set of ten .

Can u help me anchal khare ?

i need to execute in groups of lets say ten because it`s faster then one by one .

Thanks
# 4  
Old 06-01-2010
Again, that depends on how they are going to be executed ( sequential or parallel ).
if they are "independent" of each other, you can run them in parallel mode. (taking consideration of how bulky they are to handle the CPU utilization)

if you can only run the script when previous finishes, I don't think you can do anything to make it faster by grouping of them.

Also, if they are taking time, may be you can do something to tune them.
# 5  
Old 06-01-2010
they are independent of each other and i want sequential because it has 200 lines and i wanna execute them faster. like 20 30 at once.
# 6  
Old 06-01-2010
Can you post the script? what are you doing inside that?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Sending email to group in bash

In shell scripting, TestEmail is an existing group email. I am using the below command to send emails who are existed under TestEmail . Unable to receive the email. I have tried group ="id1 id2 " .Its working and i tried creating alias as well. Can we do it without creating alias or group ="id1... (1 Reply)
Discussion started by: thomas9192
1 Replies

3. Red Hat

Kcryptd - Which kernel supports MultiThread

I am currently have Centos 5.5 which consumes more CPU waiting for Kcrypt process. Later came to know that kcrypt is single threaded and hence consumes one CPU, results in performance degradation. Does any one really knows/practically experimented multithread of Kcryptd process with any of... (1 Reply)
Discussion started by: ragavendraganes
1 Replies

4. Solaris

How to find an application running on multithread?

Dear Friends, We have one T5240 server with 128vcpus in our lab.Performance of the server is very poor. Application uses only 2% of processor..I heard that single thread application performs slowly in coolthread.How can we find whether the application running on multithread or single thread? If... (7 Replies)
Discussion started by: nicktrix
7 Replies

5. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

6. Programming

[C] Multithread Server

Hi all,i'm new on this forum, excuse me for my english. I have wrote a server that accept connection from multiple client with the fork,but every client had to insert data in a linear list. The problem is that every client insert data in an own copy of the linear list and this is caused by... (7 Replies)
Discussion started by: kemistry
7 Replies

7. Programming

Multithread app - Read-Only Data

Hello, I'm coding an application using pthreads.At some point the threads will read some read-only variables.Is it safe NOT to use mutexes, in order to make the program lighter since mutex operations are resource-demanding... Thanks (1 Reply)
Discussion started by: jonas.gabriel
1 Replies

8. Programming

Multithread,libcurl

Hi i m codding a programm,it can download any packet from ftp,I use libcurl library. But i want to use threads for downloading.(Multithreading).i cant get ftp file size from ftp and divide packet small pieces,like threads use. Please share your experince with me ,thanks. (0 Replies)
Discussion started by: canerbulut
0 Replies

9. Programming

Timeout with multithread server

I wrote a server which creates a thread for every client connection. I have to include timeout function that will kill the server thread if the client doesn't respond for specific time. That too using signal(SIGALRM). For this i am using alarm() function. When the server thread detects signal it... (1 Reply)
Discussion started by: Nads
1 Replies
Login or Register to Ask a Question