#!/data/busybox sh
if [ $# -lt 2 ];then
echo "Usage $0 thread name"
exit
fi
thread=$1
name=`echo $2 | /data/busybox sed 's/[^A-Z|a-z]//g'`
echo "the thread $thread,the name $name"
if [ ! -e /proc/$thread ];then
echo "no such thread :$thread"
exit
fi
threads=`cat /proc/$thread/status | /data/busybox grep Threads | /data/busybox awk '{print $2}'`
echo "the threads is $threads"
let i=0;
let num=0;
basethread=$thread;
topthread=`ps | /data/busybox grep -v ps | /data/busybox tail -n 1 | /data/busybox awk '{print $2}'`
let diff=$topthread-$basethread
echo "the topthread $topthread,diff is $diff"
while [ $i -lt $diff ];
do
let thread=$basethread+$i
if [ ! -e /proc/$thread ];then
let i=$i+1
continue;
fi
target=`cat /proc/$thread/status | /data/busybox grep Name | /data/busybox awk -F ":" '{print $2}' | /data/busybox sed 's/[^A-Z|a-z]//g'`
if [ $target == $name ];then
echo "Success to find it,the pid is $thread"
break;
fi
tgid=`cat /proc/$thread/status | /data/busybox grep Tgid | /data/busybox awk '{print $2}'`
if [ $tgid -eq $basethread ];then
let num=$num+1;
fi
if [ $num -ge $threads ];then
echo "I have search for all the threads"
break;
fi
let i=$i+1
done
echo "at last the i is $i,the num is $num,the threads is $threads,thread is $thread"