Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How i can run two file shell in parallel and do not shared the same jvm. may be i use thread but how i run two file shell bu two thread ? File 1:

#!/bin/bash
#
# Script for running several experimentations one the same JVM
# Usage : TRACE_DIR NB_EXPE Factories... 
#

param="parameter1"
another="parameter2"

for ((i = 10; i >= 0; i -= 1))
do
echo "run my file with param another " 
done  

File 2 :

#!/bin/bash
#
# Script for running several experimentations one the same JVM
# Usage : TRACE_DIR NB_EXPE Factories... 
#

a="101" b="400" c="500"

echo "run my programme with a b c "
share|improve this question
    
    
"threads" don't exist when dealing with shell scripts - everything is run as separate processes. See lgarzo's answer for a way to run 2 scripts at the same time. –  ImaginaryRobots Mar 29 '12 at 13:31

1 Answer 1

If you'd like to run 2 shell scripts in parallel, you can use the following syntax:

script1 & script2 &

As an example take a look at the following test script (named p1):

i=1
while true;
do
    echo "1 $((i++))"
    sleep 1
    if [ $i -gt 10 ]; then break; fi
done

It will count to 10 and echo „1” before the counter. After 10 iterations it quits.

Now if you create a p2 version, just modifying the echo a bit:

    echo "2 $((i++))"

Try to run the scripts with the above syntax:

$ ./p1 & ./p2 &
1 1
2 1
1 2
2 2
1 3
2 3
1 4
2 4
1 5
2 5
1 6
2 6
1 7
2 7
1 8
2 8
1 9
2 9
1 10
2 10

As you can see, both scripts display their output and quit after 10 rounds. Note that the output is mixed, so they run in parallel.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.