This commit is contained in:
hjp 2004-05-06 12:26:36 +00:00
parent 7c90e8b0ec
commit f3f6f7006e
2 changed files with 20 additions and 0 deletions

View File

@ -17,6 +17,7 @@ install: \
$(BINDIR)/psg \
$(BINDIR)/save \
$(BINDIR)/savedate \
$(BINDIR)/findsock \
fnp: fnp.sh
fnpa: fnpa.sh

19
tiny/findsock Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
#
# Stupid little program to find the socket of stdin of the parent
# of the specified process. Normally this is used for the
# login shell to determine to which of several virtual hosts the
# user connected.
if [ $# -eq 0 ]
then
echo "Usage: $0 <pid of login shell>" >&2
exit 1
fi
pid=$1
ppid=`ps -ef | awk -v pid=$pid '$2 == pid { print $3 }'`
sock=`lsof -p $ppid 2>/dev/null | awk '$4 == "0u" && $5 == "inet" { print $9 }'`
echo $sock