sg_get_user_stats(3)
πΈ sg_get_user_stats(3) β the libstatgrab manual, bestie edition πΈ
okay so this is the page for sg_get_user_stats from the libstatgrab manual set (yep, section 3, the library-functions one π
). it's all about finding out who's logged in rn. let's get into it π«Ά
β¨ NAME β¨
sg_get_user_stats, sg_get_user_stats_r, sg_free_user_stats β grab the current logged in users π
β¨ SYNOPSIS β¨
#include <statgrab.h>
sg_user_stats *sg_get_user_stats (size_t *entries);
sg_user_stats *sg_get_user_stats_r (size_t *entries);
sg_error sg_free_user_stats (sg_user_stats *data);
like, literally just include the header and you're in π
β¨ DESCRIPTION β¨
so the user statistics module hands you back some info about the people logged on. each logon is treated separately β so if someone's logged in twice, that's two entries, no merging, no cap π
both of the getter functions, sg_get_user_stats() and sg_get_user_stats_r(), return a vector of sg_user_stats with entries elements. that's the whole vibe β¨
π¦ API Shortcut π¦
the original lays this out as a table, but tables are not the move in a terminal, so here it is as a list β same facts, cuter packaging:
sg_get_user_statsβ returnssg_user_stats *β data owner is libstatgrab (thread local)sg_get_user_stats_rβ returnssg_user_stats *β data owner is caller
and the important bit, bestie, do not skip this one: the sg_user_stats vector you get back from sg_get_user_stats_r() must be freed using sg_free_user_stats() when you don't need it anymore. the caller is responsible for doing it. no one else is gonna clean that up for you π
β¨ RETURN VALUES β¨
the structure returned is of type sg_user_stats:
typedef struct {
char *login_name;
char *record_id;
size_t record_id_size;
char *device;
char *hostname;
pid_t pid;
time_t login_time;
time_t systime;
} sg_user_stats;
and here's what each field is giving π§
login_nameβ the username which was used to log in π€record_idβ record identifier of host database containing login information (and heads up: not necessarily 0-terminated β do not assume it is, fr fr)record_id_sizeβ size of the record identifier πdeviceβ device name (eg."pts/0") of the tty assigned to the login sessionhostnameβ the (remote) hostname from where the user is logged on, eg."infoterm7.some.kind.of.domain.local","localhost","10.42.17.4"or":0.0"(in case it's a local logon via new xterm) πpidβ process identifier of the process which made the entry to the logged on users databaselogin_timeβ timestamp (time in seconds since epoch) when the user logged on β°systimeβ the timestamp when the above stats where collected in seconds since epoch β
β¨ SEE ALSO β¨
β¨ WEBSITE β¨
β¨https://libstatgrab.org/β© β go snoop, it's iconic π
ngl this one's short and sweet β but do not sleep on that sg_free_user_stats() call, that's the whole plot twist π
libstatgrab Β· 2019-03-08 β that's the source, the version and the date, all bundled up in this little sign-off. mwah, bye bestie ππβ¨
π¦ where this page comes from
- alpine 3.24: libstatgrab-doc 0.92.1-r1 Β· LGPL-2.0-or-later
- arch rolling: libstatgrab 0.92.1-2 Β· LGPL AND GPL
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- nixos 26.05: libstatgrab 0.92.1
- nixpkgs unstable: libstatgrab 0.92.1
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms