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 how is SHUT_RD โ†’ further receptions will be disallowed. No more incoming, periodt. ๐Ÿ™…โ€โ™€๏ธ
  • If how is SHUT_WR โ†’ further transmissions will be disallowed. You can still hear them, you just can't talk back. It's giving โœจboundariesโœจ.
  • If how is SHUT_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, -1 is returned, and errno is set to indicate the error. Rude of her but okay. ๐Ÿ˜ญ

๐Ÿ”ฅ ERRORS

  • EBADF โ€” sockfd is 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 in how (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 descriptor sockfd does 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 a close(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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms