plan9fox/rc/bin/tap
Ori Bernstein 5bc9b0c3ca improve usage messages (thanks henesy)
Fix inconsistencies between programs and their usage
messages,  correct instances where information seems
to be missing or lost. This  includes missing arguments,
making usage consistent with manuals, and so on.
2020-03-10 10:09:34 -07:00

56 lines
806 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 $*