1

when i test my shell code, i find that something is confused

tasklist.txt contains text:

1
2
3

and my shell code is (shell.sh):

#! /bin/bash

cat tasklist.txt | while read lines
do
  echo $lines

  cd /media/ice/0A9AD66165F33762/magnet_data/2019/修改 
  alpha/changeAlpha/runInMyComputer/80K/alpha0.01/50fs/80_1200

  mpirun -np 1 ./bin/ASDMPI cff &
done

echo "end..............."

it prints:

1
2
3

it is right!

but when i change the code to:

#! /bin/bash
cat tasklist.txt | while read lines
do
  echo $lines

  cd /media/ice/0A9AD66165F33762/magnet_data/2019/修改 
  alpha/changeAlpha/runInMyComputer/80K/alpha0.01/50fs/80_1200

  mpirun -np 1 ./bin/ASDMPI cff &
  sleep 1
done

echo "end..............."

it just prints:

1

why is the result different when i add the code: sleep 1?

my os is ubuntu18.04

=====================================================

adding content :


oldIFS=$IFS;

IFS=$'\n';

for line in $(cat tasklist.txt )

do

echo $line

nohup mpirun -np 1 ./bin/ASDMPI cff &

sleep 1

done
kill -9 $(pgrep ASDMPI)

out put:

1
nohup: appending output to 'nohup.out'
2
nohup: appending output to 'nohup.out'
3
nohup: appending output to 'nohup.out'


but

cat tasklist.txt | while read line

do

echo $line

nohup mpirun -np 1 ./bin/ASDMPI cff &

sleep 1

done

kill -9 $(pgrep ASDMPI)

out put:

1
nohup: appending output to 'nohup.out'

my "nohup mpirun -np 1 ./bin/ASDMPI cff & " may be special ,if you change the "nohup mpirun -np 1 ./bin/ASDMPI cff & " to other command ,it will show right. but i don't konw what bug with "nohup mpirun -np 1 ./bin/ASDMPI cff & " .and i will break the while?

ice
  • 29
  • 4
  • 1
    Please refer to [Markdown help](https://stackoverflow.com/editing-help#code) for tips on how to format the code. As it currently stands this is very difficult to read. – GMc Jun 01 '19 at 12:40
  • I just ran your script using some other background task, since I obviously didn't have yours, and it worked as expected. Sounds like you could do some other experiments or there's something else in your code that you perhaps haven't shown. – lurker Jun 01 '19 at 14:19
  • thank you ! may my code "mpirun -np 1 ./bin/ASDMPI cff &" has problem.and i don't know what problem. if i not run "mpirun -np 1 ./bin/ASDMPI cff &",,it show working. it is to say that if i remove "mpirun -np 1 ./bin/ASDMPI cff &" or "sleep 1" ,it will run well.(or i change the while to for ,it also run well,see my adding content ) – ice Jun 01 '19 at 14:39
  • sounds like `mpirun` is reading all of your input (the output of `cat tasklist.txt`). See https://stackoverflow.com/a/41652573/1745001. – Ed Morton Jun 01 '19 at 17:46
  • but,why the "bug" only show in my machine(ubuntu 18.04 ),but not exist in other machine(centos 6.4) (i test two machine using same code) – ice Jun 02 '19 at 09:31

0 Answers0