Parallel processing - continued


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parallel processing - continued
# 1  
Old 08-21-2013
Parallel processing - continued

Hi,
I am taking up the cue from where I was left in my earlier post ( link given below )
https://www.unix.com/shell-programmin...rocessing.html
I actually wanted to know the significance of using the Unix "wait" , which returns
the control from background to the current process.
To understand this , I created two scripts , namely
script_1.ksh
script_2.ksh

Here are the codes for the scripts:
script_1.ksh
Code:
#!/usr/bin/ksh
for i in {1..4} ;do
   ./script_2.ksh $i &
done
#wait

script_2.ksh
Code:
#!/usr/bin/ksh
   echo $1

I need to know why :
a) After the last iteration of the for loop , the shell prompt is NOT returned to the calling script(script_1.ksh) ?
If wait retrieves the control from the last executed BACKGROUND process , then the wait command should have been
called from within the for loop itself so that after every background execution of script_2.ksh for each of the loop
iteration , the control needs to come back to the parent process (script_1.ksh) so that the next iteration could be
processed . And that would effect a sequential execution of the script_2.ksh , and not parallel.

b) Uncommenting the wait command at the end of the for loop in scipt_1.ksh retrieves the control back to the parent process .
Does this mean that the wait command has brought back the control from the last background porcess kicked off when i=4 in
the for loop , and only then will any other subsequent commands in script_1.ksh will be executed. If so , how could the
loop iterated for i=2 and i=3 when it has already send the control to the background by kicking off the script_2.ksh in
its first iteration , and the for loop doesn't have a wait command within itself.
c) The wait command affecting only the latest background process . What about the ones which were spawned earlier ?


Thanks
Kumarjit.
# 2  
Old 08-21-2013
c) wait waits for all child processes to be finished. If the first one submitted takes the longest time, it will wait for that.
a) Issuing a wait after each script background submission annihilates that submission; you could run the script in foreground as well.
b) answers itself from the above.

BTW - unless you have many processors and heavily compute-bound programs, "parallel" background execution should not speed up things (dramatically). The processes will compete for resources as memory or disk, or for locks in DBs.
# 3  
Old 08-21-2013
Thanks RudiC , but I think once an external command (like script_2.ksh) is spawned to the background , the Parent PID for this process would be 1 (i.e., PID of the init process) and not the PID of script_1.ksh . So the parent to whom the status of the background process is returned to would be init , and not the main script.
So how would the wait make script_1.ksh wait for the process/es which aren't it's child after all ????

Regards
Kumarjit.
# 4  
Old 08-21-2013
The parent PID will be the script's PID. Why don't you give it a try and watch & interpret the results?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parallel processing

I have 10,000 + files, each of which I need to zip using bzip2. Is ti possible to use bash to create 8 parallel streams sending a new file to be processed from the list when one of the others has finished? (1 Reply)
Discussion started by: garethsays
1 Replies

2. Shell Programming and Scripting

Implement parallel processing

Unix OS : Linux 2.6x Shell type : Korn Hi all , This is a requirement to incorporate parallel processing of a Unix code . I have two pieces of unix code , one of which will act as a parent process . This script will invoke multiple ( say four ) instances of the second script at one go... (13 Replies)
Discussion started by: kumarjt
13 Replies

3. Programming

Parallel processing pthread

Need urgent help on thread: the goal here is the separtemask will take each image and separate different contours and for each contour in the image it will call handleobject thread. So every for loop will call the handeobject thread. However, object index variable needs to be passed in each... (0 Replies)
Discussion started by: temursalin
0 Replies

4. Shell Programming and Scripting

Parallel processing in bash?

Hi Say I am interested in processing a big data set over shell, and each process individually takes a long time, but many such processes can be pipe-lined, is there a way to do this automatically or efficiently in shell? For example consider pinging a list addresses upto 5 times each. Of... (5 Replies)
Discussion started by: jamie_123
5 Replies

5. Programming

Algorithms for Parallel Processing

Hey, I just wanted to know how many algorithms there are that cannot be accelerated by parallel processing. I know one such algorithm is Euclid's Algorithm (for GCF). does anyone know any other algorithms that cannot be accelerated by pp? if so please list the names and a general sentence of what... (2 Replies)
Discussion started by: azar.zorn
2 Replies

6. Shell Programming and Scripting

How to make parallel processing rather than serial processing ??

Hello everybody, I have a little problem with one of my program. I made a plugin for collectd (a stats collector for my servers) but I have a problem to make it run in parallel. My program gathers stats from logs, so it needs to run in background waiting for any new lines added in the log... (0 Replies)
Discussion started by: Samb95
0 Replies

7. Shell Programming and Scripting

parallel processing

hi i am preparing a set of batches for a set of files sequentially There is a folder /xyz where all the files reside now all the files starting with 01 - will be appended for one below other to form a batch batch01 then all the files starting with 02 - will be appended for one below other to... (7 Replies)
Discussion started by: mad_man12
7 Replies

8. Shell Programming and Scripting

Need Help With Parallel Processing

Hi I am looking for some kind of feature in unix that will help me write a script that can invoke multiple processes in parallel. And make sure that the multiple parallel processes complete successfully before I proceed to the next step. Someone suggested something called timespid or... (6 Replies)
Discussion started by: imnewtothis23
6 Replies

9. Shell Programming and Scripting

parallel processing

Hi I want to run two shell script files parallely. These two scripts are interacting with the database. can any body help on this Pls Regards Audippa naidu.M (3 Replies)
Discussion started by: audippa
3 Replies

10. UNIX for Dummies Questions & Answers

How to do parallel processing??

Hi All, I am working on solaris 8 sparc machine with 2 cpu. I am trying to run my application which generates files. I run multiple instance of the application, but the results don't seem to show as if it were runing parallely. When i run the application once it takes 12 secs to generate a... (1 Reply)
Discussion started by: zing
1 Replies
Login or Register to Ask a Question