MaiTiano
MaiTiano

Reputation: 711

Shell coding met segmentation fault

I have a piece of shell code run.sh like below:

#!/bin/sh
PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH
export LD_LIBRARY_PATH="../../lib"


mp3proc=mp3proc
if [ ! -f "$mp3proc" ]; then
        ln -s mp3decode $mp3proc
fi

inputsonglist="$1"
intputflag="$2

cat $inputsonglist | while read line
do
    echo "$line"
    ./"mp3proc" ${line} $inputflag
done

in which, inputsonglist is a txt file which stored full path of mp3 files list to be processed like below:

/home/user_01/music/wcbz.mp3
/home/user_01/music/wf_hh.mp3
/home/user_01/music/zj_lw.mp3
/home/user_01/music/zj_jjdzf.mp3
/home/user_01/music/zj_jsqsjywwd.mp3
/home/user_01/music/zj_sh.mp3
/home/user_01/music/zj_tbaw.mp3

mp3proc is my execetuable program which accept two parameters:

  1. full mp3 path which locates the mp3 file

  2. flag, 0 or 1

However, when I run this shell script like this:

./run.sh list.txt 0

I met following errors:

/home/user_01/music/wcbz.mp3
./run.sh: line 27: 21068 Segmentation fault      ./"mp3proc" ${line} $inputflag
/home/user_01/music/wf_hh.mp3
./run.sh: line 27: 21069 Segmentation fault      ./"mp3proc" ${line} $inputflag
/home/user_01/music/zj_lw.mp3
./run.sh: line 27: 21070 Segmentation fault      ./"mp3proc" ${line} $inputflag
/home/user_01/music/zj_jjdzf.mp3
./run.sh: line 27: 21071 Segmentation fault      ./"mp3proc" ${line} $inputflag
/home/user_01/music/zj_jsqsjywwd.mp3
./run.sh: line 27: 21072 Segmentation fault      ./"mp3proc" ${line} $inputflag
/home/user_01/music/zj_sh.mp3
./run.sh: line 27: 21073 Segmentation fault      ./"mp3proc" ${line} $inputflag

I don't know why there are "Segmentation fault" happened here ???!!!

Anybody help? Many thanks!

Upvotes: 1

Views: 233

Answers (1)

Olivier Dulac
Olivier Dulac

Reputation: 3791

1) try invoking directly mp3proc, and see it if segfaults. Then use: strace -f mp3proc and see its output

2) check the LD_IBRARY_PATH: replace with the absolute path, or modify it

Upvotes: 2

Related Questions