Thursday, October 13, 2005

[UNIX] Most Efficiency LD_LIBRARY_PATH

#! /bin/sh
                                                                                                                             
# Generate the most efficient LD_LIBRARY_PATH
#
# find out the frequency of the dynamic sharable library path and arrange
# it such that the mostly used path comes first
                                                                                                                             
if [ $# -ne 1 ]; then
        echo "Usage: $0 " 1>&2
        exit 1
fi
if [ ! -f $1 ]; then
        echo "Error. Cannot find $1" 1>&2
        exit 2
fi
                                                                                                                             
                                                                                                                             
for i in `ldd $1 | awk '{print $NF}'`
do
        echo `dirname $i`
done | sort | uniq -c | sort -k1,1 -n -r | awk ' BEGIN { printf("LD_LIBRARY_PATH=") }
            { printf("%s:",$2) }
      END { printf("\nexport LD_LIBRARY_PATH\n") }'

0 Comments:

Post a Comment

<< Home