plan9fox/rc/bin/tap
cinap_lenrek 1f02aabc6b tap: various improvements
dont use sed pipeline for indention, cache process arguments,
get process list once at start.
2012-11-12 02:12:05 +01:00

57 lines
807 B
Bash
Executable file

#!/bin/rc
rfork e
if(~ $#* 0){
echo 'Usage: ' $0 '[ pid ... ]' >[1=2]
exit usage
}
f=/proc/*/fd
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-)
shift
shift
shift
}
}
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-)
}
shift
}
}
tracepid $*