plan9fox/rc/bin/tap

57 lines
806 B
Text
Raw Permalink Normal View History

2012-03-09 22:10:17 +00:00
#!/bin/rc
2012-05-26 19:50:10 +00:00
rfork e
2012-03-09 22:10:17 +00:00
if(~ $#* 0){
echo 'usage:' $0 '[ pid ... ]' >[1=2]
exit usage
}
f=/proc/*/fd
2012-03-09 22:10:17 +00:00
fn otherqid {
x=`{echo $1 | sed 's/[12]$//'}
switch($1){
case $x^1
echo $x^2
case $x^2
echo $x^1
}
}
fn traceqid {
while(! ~ $#* 0){
echo $t '['$2']' $3 $1
t=(' ' $t)
tracepid `{grep -n `{otherqid $1} $f >[2]/dev/null | sed 's!^/proc/([^/]+)/.*!\1!g'}
t=$t(2-)
2012-03-09 22:10:17 +00:00
shift
shift
2012-03-09 22:56:05 +00:00
shift
2012-03-09 22:10:17 +00:00
}
}
fn tracepid {
while(! ~ $#* 0){
a=ap$1
v=av$1
if(~ $$v $1){
echo $t $1 $$a ' ...'
}
if not {
$v=$1
$a=`{cat /proc/$1/args >[2]/dev/null}
if(~ $$a ''){
s=`{cat /proc/$1/status >[2]/dev/null}
$a=$s(1)
}
echo $t $1 $$a
t=(' ' $t)
traceqid `{awk '/\|/{q=substr($5,2);print q" "$1" "$10}' /proc/$1/fd >[2]/dev/null}
t=$t(2-)
2012-03-09 22:10:17 +00:00
}
shift
}
}
tracepid $*