Professional Documents
Culture Documents
# ps -ef|grep ftp
root 20620 29427 0 12:02:45 ttypc 0:00 ftp bj71s020
只留下进程 20620:
q4> keep p_pid==20620
kept 1 of 142 struct proc's, discarded 141
看看 20620 的进程名字:
q4> print p_comm
p_comm
"ftp"
实 验
# chmod g-x,g+s /tmp/top.out
# lockfile /tmp/top.out
# cat /tmp/top.out
目 标 :
1 , 跟 踪 cat 进 程 , 找 出 它 sleep 的 原 因
2,继续跟踪锁的 owner,找到 lockfile 进程
q4> load struct proc from proc_list next p_factp max nproc
loaded 117 struct procs as a linked list (stopped by null pointer)
q4> keep p_pid==25002
kept 1 of 117 struct proc's, discarded 116
q4> print p_comm
p_comm
"cat"
q4> trace pile
stack trace for process at 0x0`43640040 (pid 25002), thread at 0x0`47c2b040
(tid
58447)
process was not running on any processor
_swtch+0xd0
_sleep+0x1cc
locked+0xd84
vx_rdwr+0x2b8
vno_rw+0x80
read+0x10c
syscall+0x768
$syscallrtn+0x0
q4> trace -u pile
......
LEVEL FUNC ARG0 ARG1
# ps -ef|grep 3602
root 3643 3633 3 17:35:46 ttyp4 0:00 grep 3602
root 3602 2021 0 17:26:23 ttyp3 0:00 ./lockfile /tmp/top.out
实验:
(同前)
# lockfile /tmp/top.out
# cat /tmp/top.out
分析过程:
# ps -ef|grep cat
root 27616 26881 3 16:02:20 ttyp1 0:00 grep cat
root 26913 26888 0 10:35:34 ttyp3 0:00 cat /tmp/top.out
# q4 /stand/vmunix /dev/mem
...
/*找到 sleep 中的 cat 进程*/
q4> load struct proc from proc_list next p_factp max nproc
loaded 178 struct procs as a linked list (stopped by null pointer)
q4> keep p_pid==26913
kept 1 of 178 struct proc's, discarded 177
q4> print p_comm
p_comm
"cat"
/*找到线程*/
q4> load struct kthread from p_firstthreadp next kt_nextp max nkthread
loaded 1 struct kthread as a linked list (stopped by null pointer)
q4> print kt_tid
kt_tid
29832
/*寻找线程*/
q4> history
HIST NAME LAYOUT COUNT TYPE COMMENTS
1 <none> list 178 struct proc stopped by null pointer
2 <none> mixed? 1 struct proc subset of 1
3 <none> list 1 struct kthread stopped by null pointer
4 <none> array 200 struct locklist stopped by max count
5 <none> mixed? 9 struct locklist subset of 4
6 <none> mixed? 1 struct locklist subset of 5
7 <none> array 1 struct vnode stopped by max count
8 <none> array 1 struct vx_inode stopped by max count
9 <none> mixed? 1 struct locklist copy of 6
10 <none> array 1 struct proc stopped by max count
11 <none> array 0 struct kthread stopped by null pointer
q4> forget 11
q4> forget 10
q4> load struct kthread from ll_kthreadp
loaded 1 struct kthread as an array (stopped by max count)
q4> print -tx kt_tid
kt_tid 0x7487
/*找到了:线程号 0x7487*/
# cat lswchan
#! /usr/bin/sh
ps -el | awk '{
mylen=length($11);
if ( mylen==6 || mylen==7 )
{
print "0x" $11 "?r" | "adb64 -k /stand/vmunix /dev/mem | tail -1 > /tmp/t";
"cat /tmp/t" | getline s;
close("/tmp/t");
printf("%s\t%-16s%s\n", $4, $14, s);
}
else
{
printf("%s\t%-16s%s\n", $4, $14, $11);
}
}'
分享:
例:
# ps -ef|grep inetd
root 811 1 0 Sep 9 ? 1:53 /usr/sbin/inetd -l
root 4805 4306 2 11:35:56 pts/tf 0:00 grep inetd
# gdb /usr/sbin/inetd 811
...
(gdb) dumpcore
Dumping core to the core file core.811
(gdb) quit
...
# grep LANG core.811
...
^OM-+X^?^?@/usr/sbin/inetd-lLANG=CPATH=/sbin:/usr/sbin:/usr/binTZ=EAT-8NI
...