Executing two commands in parallel

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing two commands in parallel
# 1  
Old 03-25-2011
Executing two commands in parallel

I am stuck into a situation where i want to execute a command in my shell script well along with a previous command in order to achieve something but i am not figuring out a way.
here is a snippet:

service management restart
rm -rf lock.file

in the above, if you see, i am trying to restart a service first.
What happens is that as soon as that command of restart starts running, there is a temporary lock file created.
However, that lock file is causing some performance issues (the restart takes a long time because of the lock file).
Now, i want to override this event by deleting the lock file as soon as the restart command runs.

so, i am looking for way where i can delete the file as soon as the restart command starts running, which i am sure will solve my problem

Is there any way where i can run both commands in parallel (executing both commands together)
Please can any one guide me on this ?
# 2  
Old 03-25-2011
I think you can run your first process in background by putting & at the end of the command and then run rm command.
This User Gave Thanks to pravin27 For This Post:
# 3  
Old 03-25-2011
The '&' will put the job in background. but it does not move to the next command to execute until the existing job is complete.
so, in my case, the rm command will still wait until the job in the background completes.
# 4  
Old 03-25-2011
No & does move the job to next line
This User Gave Thanks to dinjo_jo For This Post:
# 5  
Old 03-25-2011
Thanks folks.
My bad. i dint try it. it works Smilie

Thanks a lot.
# 6  
Old 03-25-2011
ok .. now there is one more thing we might need to do while doing things in parallel.

suppose there 4 commands
cmd1,cmd2, cmd3, cmd4

goal is :
run cmd1 and cmd2 in parallel, once both are done move on to execute cmd3 and cmd4 in parallel, exit the script once both are done
cmd1 & 

cmd2 & 

wait $pid1
wait $pid2

cmd3 & 

cmd4  & 

wait $pid3
wait $pid4


Last edited by Franklin52; 03-25-2011 at 07:15 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Executing SQL's in parallel

Hi Folks, I have requirement to pull a bunch of SQL's from a table in DB and execute them in parallel and update the status of each query as and when they complete. Can you please help me with ideas on how this can be achieved? create table list_of_sql ( id number, full_sql... (3 Replies)
Discussion started by: member2014
3 Replies

2. Shell Programming and Scripting

Parallel RM and FIND commands conflicting

Hi all. Long time!! Hope you're doing well.. I've stumbled on a peculiar siutaion here, and would expect help from this forum on a clean resolution. We are running an rm and find command simultaneously from two different Unix sessions of the same user(let's say USER01) and on the same... (3 Replies)
Discussion started by: kumarjt
3 Replies

3. Shell Programming and Scripting

Executing Multiple Queries in parallel in Shell

I have n number of SQL queries needs to executed in Shell. Result of this query need to assign in a variable. Once all the queries are executed script needs to exit. Sample Query: SQL 1: Select Count(*) from TABLE GROUP BY COL1,COL2 SQL 2: Select Count(*) from TABLE GROUP BY COL1,COL2 ... (2 Replies)
Discussion started by: Niranjancse
2 Replies

4. Shell Programming and Scripting

Help with executing parallel sessions for same shell script with different but fixed parameters

Hi Experts, There is a shell script that accepts positional parameter between 1-25 to execute case statement of script depending upon the parameter passed. Now I need to run all the 25 sessions parallely. In each option of case statement it is connecting with sqlplus and executing a select... (11 Replies)
Discussion started by: Opamps123
11 Replies

5. Shell Programming and Scripting

Executing commands

I need to execute a command to run my script several times with varying parameters perl ex.pl -b 130198 -e 130884 -c plot plot.txt 1_plot.txt perl ex.pl -b 1345 -e 1308 -c plot plot.txt 2_plot.txt perl ex.pl -b 1345567 -e 130898 -c plot plot.txt 3_plot.txt . . . 100's of excutions ... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

6. Shell Programming and Scripting

Executing many commands at once

Hi, I want to run these two commands one after the other. awk 'BEGIN {OFS="\t"} {print $2}' sort -u rather than typing awk 'BEGIN {OFS="\t"} {print $2}' file1 > file2, then sort -u file2 > file3. Is it possible to run both commands on file1 then get output file3? Its kinda hard for... (5 Replies)
Discussion started by: kylle345
5 Replies

7. Red Hat

How commands are executing ?

Hi Folks, I have a small doubt, the binary commands under /bin and /sbin as well as other path binary files, if you peek deep into that, you can find the difference in the way of normal perl programming and some commands will be like binary files. how are the commands executing like the... (3 Replies)
Discussion started by: gsiva
3 Replies

8. Shell Programming and Scripting

Executing scripts in Parallel

Hi All, I have 3 shell scripts, Script1,Script2 and Script3. Now I want to run Script1 and Script2 in parallel and Script3 should depend on successful completion of both Script1 and Script2. Could you please suggest an approach of acheiving this... Thanks in advance (2 Replies)
Discussion started by: itsme_maverick
2 Replies

9. Shell Programming and Scripting

Execute commands parallel in a for loop ?

Hi, please can someone point me in the right direction with a shell scripting problem. I want to execute a command in a for loop and the command should be started not one-by-one meaning the for loop is waiting for the exit code , it should be started in parallel. I have a plain text file... (3 Replies)
Discussion started by: networkfre@k
3 Replies

10. Shell Programming and Scripting

Executing mpirun commands

Basically, I would like to run an mpirun query on my web server to query your databases via yours when using the BLAST program, however the server seems not able to execute even basic mpirun programs such as cpi (to calculate pi). Are there any settings I should take note of? I am running Perl... (0 Replies)
Discussion started by: tesswulf
0 Replies
Login or Register to Ask a Question

Featured Tech Videos