make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / pipekill
blob182a9e5040bf0a1b5c204b1b75075d7220ad920c
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 pipekill - Send signal to a process on the other end of the given pipe filedescriptor
10 =cut
12 EOF
15 if [ .${1:0:1} = .- ]; then
16 signal=$1
17 shift
18 else
19 signal=''
22 if [ "$1" -ge 0 ] 2>/dev/null; then
23 my_fd=$1
24 pipe=`readlink -n /proc/$$/fd/$my_fd`
25 pipe_number=${pipe//[!0-9]/}
26 pipe=`find /proc -maxdepth 3 -mindepth 3 -lname "pipe:\[$pipe_number\]" -print -quit 2>/dev/null`
27 other_pid=${pipe:6}; other_pid=${other_pid%%/*}
29 if [ -n "$other_pid" ]; then
30 kill $signal "$other_pid"
31 else
32 echo "pipekill: piped process not found." >&2
33 exit 1
35 else
36 echo "Usage: pipekill [-<signal>] [<fdnum>]" >&2
37 exit 1