shutdown(2)
๐ shutdown โ the bestie who knows when to say bye
Okay so shutdown(2) is a system call, she lives in the System Calls Manual, and she's the one who handles the โจgoodbyeโจ part of a full-duplex connection. Not the whole vibe โ just part of it. We love a queen who knows her lane. ๐
๐ธ LIBRARY
Standard C library (libc, -lc) โ she's already in the building, bestie, no extra linking needed.
โจ SYNOPSIS
#include <sys/socket.h>
int shutdown(int sockfd, int how);
๐ฆ DESCRIPTION
So like, the shutdown() call causes all or part of a full-duplex connection on the socket associated with sockfd to be shut down. Choose your fighter:
- If
howisSHUT_RDโ further receptions will be disallowed. No more incoming, periodt. ๐ โโ๏ธ - If
howisSHUT_WRโ further transmissions will be disallowed. You can still hear them, you just can't talk back. It's giving โจboundariesโจ. - If
howisSHUT_RDWRโ further receptions and transmissions will be disallowed. Full send on the goodbye. Both directions, gone, iconic. ๐
๐ RETURN VALUE
- On success, zero is returned. Queen behavior. ๐
- On error,
-1is returned, anderrnois set to indicate the error. Rude of her but okay. ๐ญ
๐ฅ ERRORS
EBADFโsockfdis not a valid file descriptor. Not a real fd, not a real one of us, we don't know her. ๐ซEINVALโ An invalid value was specified inhow(but see BUGS below, it's a whole situation).ENOTCONNโ The specified socket is not connected. Ma'am, there's no connection, what are we even shutting down? ๐ENOTSOCKโ The file descriptorsockfddoes not refer to a socket. Bestie that's not a socket, that's justโฆ a file. ๐ต
๐ STANDARDS
POSIX.1-2024. Certified. ๐
๐ฐ๏ธ HISTORY
POSIX.1-2001, 4.4BSD (first appeared in 4.2BSD). She's old money, been doing this since the 4.2BSD era. Vintage but still relevant, we stan a timeless icon. โญ
๐ง NOTES
The constants SHUT_RD, SHUT_WR, and SHUT_RDWR have the value 0, 1, and 2, respectively โ in that order, no cap โ and they're defined in <sys/socket.h> since glibc-2.1.91. So like, they've been living there for a minute. ๐
๐ BUGS
Okay so lowkey a cautionary tale, listen up:
Checks for the validity of how are done in domain-specific code, and before Linux 3.7 not all domains performed these checks. Most notably, UNโ
จ domain sockets justโฆ simply ignored invalid values. Like, straight up didn't care, no vibe check, nothing. ๐ญ
This problem was fixed for UNIX domain sockets in Linux 3.7. So if you're on something ancient, bestie, watch yourself. ๐ซถ
๐ SEE ALSO
close(2), connect(2), socket(2), socket(7) โ the whole friend group, go read them too, iykyk. ๐
tl;dr: you want to half-close a socket?shutdown()is your girl. You want to fully destroy it? That's aclose(2)conversation, different bestie, different energy. ๐
This little love letter comes to you courtesy of Linux man-pages 6.20, dated 2025-10-29. Mwah, go close your sockets responsibly. โจ๐ฆ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: BSD-4-Clause-UC
- Copyright 1983-1991, The Regents of the University of California
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms