SOCKDOWN(1)
π SOCKDOWN β the little page that says "bye felicia" to half your socket π
okay bestie, so this is sockdown from the netpipes family, and it's one of those tiny icon commands that does exactly one thing and does it flawlessly. it's part of netpipes 4.2, it lives in the General Commands Manual, and honestly? it's giving "quiet kid in class who is actually the strongest person here." π¦
β¨ NAME β¨
sockdown β literally just shutdown(2) on a socket. that's it. that's the whole vibe. π
πΈ SYNOPSIS πΈ
sockdown [ fd [how] ]
π DESCRIPTION π
bestie, listen. sockdown performs the shutdown(2) system call on one of its file descriptors, and you get to pick which one with fd. the how tells it what flavor of shutdown you want, and here are your options, no cap:
writeonlyβ convert to write-only file descriptor0β convert to write-only file descriptorwriteonlyβ symbolic for same as above (yes, it's listed twice in the original, and we respect the original around here π )1β convert to read-only file descriptorreadonlyβ symbolic for same as above2β complete shutdown. no more reads or writes are allowedtotallyβ symbolic for same as above
and the defaults? the default fd is 1 (that's stdout) and the default how is 1. so if you just type sockdown with zero thoughts, it does that. periodt. β¨
π EXAMPLES π
okay so imagine you have a machine that can perform a service β in this case, conversion from ASCII to fancy postscript β and you want to serve it up:
server$ faucet 3000 --in --out enscript -2rGhp -
you may then connect to it with a hose. HOWEVER. π¨ the first example enters deadlock:
client$ hose server 3000 -in -out \
sh -c " cat blah.txt & cat > blah.ps "
here's what's happening, and it's giving tragic. the enscript blocks waiting for input from the socket because not all of the client processes have exited. while the cat blah.txt is finished, the cat > blah.ps is not, and will not be finished until the remote enscript process finishes writing. and the enscript process will not finish writing until it is finished reading β but that clientβserver half of the socket is still open and will not be closed until all the client processes are done. the result is deadlock. π literally everyone standing in the hallway waiting for the other person to move.
so. we use sockdown to close half of the pipe:
client$ hose server 3000 -in -out \
sh -c " ( cat blah.txt ; sockdown ) & cat > blah.ps "
this way when the cat blah.txt is done, half of the socket is shut down and the remote enscript process runs out of input, causing it to flush its output and exit, so eventually the whole mess finishes cleanly. ate. no crumbs. π§
Note: the&on the hose is necessary to prevent another deadlock. if we simply used the;to serialize the twocatprocesses, it is possible that theenscriptwould fill up its write buffer before the firstcatwas done, causing both processes to block and preventing the secondcatfrom draining the pipe. so don't do that. fr fr. π
of course, that idiomatic usage of hose is so useful that it is a special form:
client$ hose server 3000 -slave < blah.txt > blah.ps
Ian Stirling <root@mauve.demon.co.uk> informs me that sockdown can be used in Linux's /proc/pid/fd/ directories to tear down hung network connections. I have since used this myself on a wedged MOMspider. to try this, you have to know the PID of the program and the file descriptor of the wedged socket (can sometimes be found by running strace and seeing if the program is stuck in a read(2) system call). if the PID is 991 and the socket's descriptor is 5, you do this as root:
bash# sockdown 1 2 > /proc/991/fd/5
π«Ά ERRORS π«Ά
- Socket operation on non-socket
- Invalid argument (seen on Solaris) β the
fdyou specified does not refer to a socket. this happens when you runsockdownby itself (it is unlikely that any of the file descriptors attached to an interactive shell are actually sockets) or if you goof up yourfaucet/hosecommand and forgot todup(2)one of your descriptors. - Bad file number β you gave it a bad file number for
fd. if you have enough skill to actually generate this error, you probably know what is wrong. π
if you encounter any other errors, clue me in.
π₯ SEE ALSO π₯
netpipes (1), faucet (1), hose (1), getpeername (1), socket (2), shutdown (2),
π NOTES π
any normal human would assume a program this simple has to be bug free, but I am an experienced programmer. π
just avoid doing anything funky like passing sockdown strings and it should serve you well. you should not have to pass it any arguments unless you are doing something fairly funky.
perhaps I should ditch the shutdown -a semantics on hose since a sockdown 1 2 would do the job.
β CREDITS β
Ian Stirling <root@mauve.demon.co.uk>, for the idea of using this program in /proc on a Linux machine. absolute legend behaviour, honestly. π
π COPYRIGHT π
Copyright (C) 1995-1998 Robert Forsman
this program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
this program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
you should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
πΈ AUTHOR πΈ
Robert Forsman thoth@purplefrog.com Purple Frog Software http://web.purplefrog.com/~thoth/
and that's the whole page, bestie!! this one's from July 7, 1998, shipped as part of netpipes 4.2 in the General Commands Manual β so it's older than most of us and still out here closing half-pipes like a queen. go shut down a socket. slay. π β¨π¦
π¦ where this page comes from
- debian bookworm: netpipes 4.2-8+b1
- debian trixie: netpipes 4.2-8+b2
- ubuntu jammy: netpipes 4.2-8build1
- ubuntu noble: netpipes 4.2-8build1
- ubuntu questing: netpipes 4.2-8.1
- ubuntu resolute: netpipes 4.2-8.1build1
- ubuntu stonking: netpipes 4.2-8.1build1
- Copyright 1995 by Robert Forsman
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms