TIOCSWINSZ(2const)

✨ TIOCGWINSZ, TIOCSWINSZ ✨

okay bestie so you found yourself in the TIOCSWINSZ section of the 2const manual, and honestly? it's giving window resize energy πŸ’… this is the get-and-set-window-size duo.


🫢 LIBRARY

Standard C library (libc, -lc) β€” the classic, the icon, no cap.


🌸 SYNOPSIS

#include <asm/termbits.h>  /* Definition of TIOC*WINSZ constants */
#include <sys/ioctl.h>

int ioctl(int fd, TIOCGWINSZ, struct winsize *argp);
int ioctl(int fd, TIOCSWINSZ, const struct winsize *argp);

#include <asm/termios.h>

struct winsize {
    unsigned short ws_row;
    unsigned short ws_col;
    unsigned short ws_xpixel;  /* unused */
    unsigned short ws_ypixel;  /* unused */
};

so you're calling ioctl() with one of two constants and handing it a pointer to a struct winsize. TIOCGWINSZ gets, TIOCSWINSZ sets. and yeah, the header for the constants is asm/termbits.h, but the struct lives over in asm/termios.h, so you need both. annoying? yes. iconic? also yes 😭


πŸ’– DESCRIPTION

The window sizes are kept in the kernel, but β€” plot twist β€” the kernel doesn't actually use them. lowkey the kernel is just holding them for you like a supportive bestie holding your bag πŸ‘œ

exception: virtual consoles. In that one case, the kernel will update the window size when the size of the virtual console changes β€” for example, by loading a new font. so if fonts are your thing, this matters, otherwise it's vibes only.

TIOCGWINSZ Goal: get window size. πŸ“

TIOCSWINSZ Goal: set window size. ✍️

and when the window size changes, a SIGWINCH signal gets sent to the foreground process group. that's right, your terminal is literally sending a signal, main character behavior, it just wants to tell you the shape of things changed πŸ”₯


⭐ RETURN VALUE

On success, 0 is returned. On error, -1 is returned, and errno is set to indicate the error. so check your errno, bestie, it's not gonna text you first πŸ’€


πŸ‘‘ SEE ALSO


mwah, that's the whole page, no filler, no fluff, fr fr πŸ¦‹ this came from Linux man-pages 6.20, dated 2026-02-08 β€” go off, go resize something, periodt πŸ’…βœ¨

πŸ“¦ 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: GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms