explain_shmat_or_die(3)
π explain_shmat_or_die β library functions manual, bestie edition π
okay so. hi. you're in section 3 of the manual pages, which is the "library functions" zone, and today's main character is explain_shmat_or_die(3). she's here to help you attach shared memory and, if it all goes sideways, tell you why before dramatically exiting. no cap. β¨
π NAME π
explain_shmat_or_die β shared memory attach and report errors π«Ά
β¨ SYNOPSIS β¨
#include <libexplain/shmat.h>
void *explain_shmat_or_die(int shmid, const void *shmaddr, int shmflg);
void *explain_shmat_on_error(int shmid, const void *shmaddr, int shmflg);
π¦ DESCRIPTION π¦
so there's two functions here and they're basically twins, except one of them is way more dramatic than the other. π
The explain_shmat_or_die function is what you call when you wanna call the shmat(2) system call. If it fails, an explanation gets printed to stderr (it gets that explanation from the explain_shmat(3) function, she's the one doing the actual explaining), and then the process just terminates by calling exit(EXIT_FAILURE). like. girl. gone. π
The explain_shmat_on_error function is also used to call the shmat(2) system call. On failure an explanation is printed to stderr, again grabbed from explain_shmat(3) β but this one still returns to the caller. she explains and she moves on. mature of her honestly. πΈ
and now the arguments, which are all literally "pass this straight through to shmat(2), no notes":
shmidβ theshmid, exactly as to be passed to theshmat(2)system call.shmaddrβ theshmaddr, exactly as to be passed to theshmat(2)system call.shmflgβ theshmflg, exactly as to be passed to theshmat(2)system call.
that's it. that's the whole vibe. you hand over the exact same stuff you'd hand to shmat(2) and these functions do the rest. π
π RETURN VALUE π
explain_shmat_or_die only returns on success β and if you wanna know what success looks like, go peek at shmat(2) for more information. On failure? she prints an explanation and exits. she does not return. that's not a return value bestie, that's a goodbye. π
explain_shmat_on_error always returns the value return by the wrapped shmat(2) system call. yes, always. even the sad ones. π₯²
π§ EXAMPLE π§
The explain_shmat_or_die function is intended to be used in a fashion similar to the following example:
void *result = explain_shmat_or_die(shmid, shmaddr, shmflg);
look at her. one line. iconic. β
π₯ SEE ALSO π₯
shmat(2)β shared memory attachexplain_shmat(3)β explainshmat(2)errorsexit(2)β terminate the calling process
iykyk, these three are the whole group chat. π
π COPYRIGHT π
libexplain version 1.4 Copyright (C) 2011 Peter Miller
and that's the whole page, bestie!! π thanks for reading all the way to the bottom, you're literally the best. this was explain_shmat_or_die(3) from the Library Functions Manual, brought to you by libexplain version 1.4, copyright (C) 2011 Peter Miller β mwah, stan, bye!! πβ¨π¦
π¦ where this page comes from
- debian bookworm: libexplain-dev 1.4.D001-12+b1 Β· LGPL-3.0-or-later
- debian trixie: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- ubuntu jammy: libexplain-dev 1.4.D001-12 Β· LGPL-3.0-or-later
- ubuntu noble: libexplain-dev 1.4.D001-13 Β· LGPL-3.0-or-later
- ubuntu resolute: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- Copyright (C) 2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms