Chinaunix首页 | 论坛 | 博客
  • 博客访问: 373287
  • 博文数量: 43
  • 博客积分: 1493
  • 博客等级: 上尉
  • 技术积分: 660
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-01 10:57
文章分类

全部博文(43)

文章存档

2015年(1)

2013年(1)

2011年(6)

2010年(13)

2009年(13)

2008年(9)

分类: LINUX

2010-08-18 14:00:34

#!/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"



用法:
./show_thread.sh  1882 pvplayer
第一个参数是通过ps看到的某个你需要关心的进程;
第二个参数是我们要查找的名字叫做pvplayer的线程,这个名字需要去掉里面的空格,并且是区分大小写的;

阅读(2311) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~