Operating System - HP-UX
1752425 Members
5322 Online
108788 Solutions
New Discussion юеВ

Running a command Simultaniousely.

 
Ramesh.K.R.
Regular Advisor

Running a command Simultaniousely.

Hi Experts,

I have a peculiar requirement.
I want to run a command, from within a script.
But, the catch is to run two instances of the same command, simultaniousely.
How can i do this ??

Regards,
Ramesh
hai
6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: Running a command Simultaniousely.

You put them in the background:
command &
command &
wait # waits for both
Ivan Krastev
Honored Contributor

Re: Running a command Simultaniousely.

You can try to run both commands into background:

command &
command &



regards,
ivan
Ramesh.K.R.
Regular Advisor

Re: Running a command Simultaniousely.

Hi,

I have already tried this ...

Sorry, i forgot to add ome more point, this perticular command dosen't take any time to execute ..... !!!
And the important condition with my command is, the secand instance should fail, pointing that another instance of the command is running ..
(the time lag for the command is almost non-existeant)

Ramesh
hai
Dennis Handly
Acclaimed Contributor

Re: Running a command Simultaniousely.

>And the important condition with my command is, the second instance should fail, pointing that another instance of the command is running

Then you will have to modify your command to detect this. Create a lock file with the PID of the first in a file? Using $! after you background a command will give its PID.

>(the time lag for the command is almost non-existent)

What are you trying to do, write a test case?
Or do real work?
Ramesh.K.R.
Regular Advisor

Re: Running a command Simultaniousely.

Hi,

Its a TeMIP (OV Product) fcl command.

The command itself has a in-built mechanism to look for running proceses. It fails, if it detects the command running. But, the problem is, it dosen't time to execute & come out ...
But, we have to produce a test case scenario for this ..

Regards,
Ramesh.K.R.
hai
Dennis Handly
Acclaimed Contributor

Re: Running a command Simultaniousely.

>we have to produce a test case scenario for this

Then try a wrapper around your fcl.
In the wrapper, you will spin in a loop checking to see if a file exists. If it does, then execute fcl.
# wait for signal-file
while [ ! -f signal-file ]; do
: nothing here to see
done
fcl ...

Then do:
wrapper-command &
wrapper-command &
sleep 5 # make them work up a sweat
touch signal-file

Both wrappers should start up fcl about the same time.