getutent(3) Library Functions Manual getutent(3) getutent, getutid, getutline, pututline, setutent, endutent, utmpname - utmp C (libc, -lc) #include struct utmp *getutent(void); struct utmp *getutid(const struct utmp *ut); struct utmp *getutline(const struct utmp *ut); struct utmp *pututline(const struct utmp *ut); void setutent(void); void endutent(void); int utmpname(const char *path); New applications should use the POSIX.1-specified "utmpx" versions of these functions; see STANDARDS. utmpname() sets the pathname of the utmp-format file for the other utmp functions to access. If utmpname() is not used to set the pathname before the other functions are used, they assume _PATH_UTMP, as defined in . setutent() utmp. , . endutent() utmp. , . getutent() , utmp. , . utmp(5). getutid() , utmp, ut. ut->ut_type RUN_LVL, BOOT_TIME, NEW_TIME OLD_TIME, getutid() , ut_type ut->ut_type. ut->ut_type INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS DEAD_PROCESS, getutid() , ut_id ut->ut_id. getutline() , utmp. , ut_type USER_PROCESS LOGIN_PROCESS, , ut_line ut->ut_line. pututline() utmp ut utmp. , , getutid() . , pututline() . getutent(), getutid(), and getutline() return a pointer to a struct utmp on success, and NULL on failure (which includes the "record not found" case). This struct utmp is allocated in static storage, and may be overwritten by subsequent calls. pututline() ut; NULL. utmpname() 0 -1 . On failure, these functions errno set to indicate the error. ENOMEM . ESRCH . setutent(), pututline() getut*() , open(2). /var/run/utmp , /var/log/wtmp attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |getutent() | | MT-Unsafe init | | | | race:utent race:utentbuf | | | | sig:ALRM timer | +----------------------------+----------------------------------------------------------+--------------------------+ |getutid(), getutline() | | MT-Unsafe init | | | | race:utent sig:ALRM | | | | timer | +----------------------------+----------------------------------------------------------+--------------------------+ |pututline() | | MT-Unsafe race:utent | | | | sig:ALRM timer | +----------------------------+----------------------------------------------------------+--------------------------+ |setutent(), endutent(), | | MT-Unsafe race:utent | |utmpname() | | | +----------------------------+----------------------------------------------------------+--------------------------+ utent race:utent , setutent(), getutent(), getutid(), getutline(), pututline(), utmpname() endutent(), . . XPG2, SVr4. XPG2 SVID 2 pututline() void (AIX, HP-UX). HP-UX _pututline() pututline(). Linux . POSIX.1-2001 POSIX.1-2008, SUSv1, , #include struct utmpx *getutxent(void); struct utmpx *getutxid(const struct utmpx *); struct utmpx *getutxline(const struct utmpx *); struct utmpx *pututxline(const struct utmpx *); void setutxent(void); void endutxent(void); glibc <>", struct utmpx, Linux struct utmp. , glibc utmpxname(), POSIX.1. utmpx utmp , , /var/*/utmpx /var/*/wtmpx. , Linux glibc utmpx, utmp . <>, , <> (, getutxent() getutent()). glibc The above functions are not thread-safe. glibc adds reentrant versions #include int getutent_r(struct utmp *ubuf, struct utmp **ubufp); int getutid_r(struct utmp *ut, struct utmp *ubuf, struct utmp **ubufp); int getutline_r(struct utmp *ut, struct utmp *ubuf, struct utmp **ubufp); glibc (. feature_test_macros(7)): getutent_r(), getutid_r(), getutline_r(): _GNU_SOURCE || /* Since glibc 2.19: */ _DEFAULT_SOURCE || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE GNU, _r. ubuf, , . 0 *ubufp. -1. utmpx ( POSIX.1 ). utmp, , . , getpwuid(3) ttyname(3). #include #include #include #include #include #include #include int main(void) { struct utmp entry; if (system("echo before adding entry:;who") == -1) err(EXIT_FAILURE, "system"); entry.ut_type = USER_PROCESS; entry.ut_pid = getpid(); strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/")); /* only correct for ptys named /dev/tty[pqr][0-9a-z] */ strcpy(entry.ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty")); entry.ut_time = time(NULL); strcpy(entry.ut_user, getpwuid(getuid())->pw_name); memset(entry.ut_host, 0, UT_HOSTSIZE); entry.ut_addr = 0; setutent(); if (pututline(&entry) == NULL) err(EXIT_FAILURE, "pututline"); if (system("echo after adding entry:;who") == -1) err(EXIT_FAILURE, "system"); entry.ut_type = DEAD_PROCESS; memset(entry.ut_line, 0, UT_LINESIZE); entry.ut_time = 0; memset(entry.ut_user, 0, UT_NAMESIZE); setutent(); if (pututline(&entry) == NULL) err(EXIT_FAILURE, "pututline"); if (system("echo after removing entry:;who") == -1) err(EXIT_FAILURE, "system"); endutent(); exit(EXIT_SUCCESS); } getutmp(3), utmp(5) () Azamat Hackimov , Dmitry Bolkhovskikh , Vladislav , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () . Linux man-pages 6.18 8 2026 . getutent(3)