I have used exec 3<>/dev/tcp/192.168.0.101/6435
to establish a TCP connection with 192.168.0.101:6435. And I have received as well as sent a few messages with the pipe
command.
Now, I want to terminate the TCP connection. But, with ss -anpet
I can see that bash itself holds this connection, without forking a child process.
I tried to send signal 9 and 15 to the bash process, but as you know, bash cannot kill itself.
So, can I terminate the TCP connection I have established without terminating the pts I am using (neither killing it by root nor sending Ctrl+D)?
bash
with that shell?bash
certainly can kill itself - though that's not actually what you want to do here!pipe
command you're using and which I can't find on my system? Which package doespipe
comes from? What (example) parameters can you pass to it to send/receive data over the/dev/tcp/...
connection? Thanks./dev/tcp
, even cannot find/dev/tcp
itself. But, it seems a special usage that you can send/receive data withpipe
and this kind of files. It is said that use/dev/tcp/ip/port
for tcp connections, and/dev/udp/ip/port
for udp packages. For my English is not very good, I don not know how to explain it properly. Please feel free to edit the question and post an answer.pipe
command that you mention. I looked athttps://github.com/clsr/sedbot/blob/master/sedbot.bash
. There's nopipe
command there. It defines two functions:readmsg
andsendmsg
to read/write from/to the connection respectively.readmsg
usesIFS= read -r -u 3 -t "$READ_TIMEOUT" line
to read from file-descriptor 3 into the variableline
, andsendmsg
usesecho "$(date +%s.%N) >>> $line" >&4
to write into file descriptor 4. Anyway, this clarifies the full method. The "pipe
command" mention still remains a mystery to readers.