---
name: "sg_get_user_stats"
section: "3"
platform: "linux"
package: "libstatgrab"
version: "0.92.1-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/sg_get_user_stats"
---

# sg\_get\_user\_stats(3)

get the current logged in users

## NAME

sg\_get\_user\_stats, sg\_get\_user\_stats\_r, sg\_free\_user\_stats - get the current logged in users

## SYNOPSIS

```
FC#include <statgrab.h>F[0]
```

FCsg\_user\_stats \***sg\_get\_user\_stats**F\[0\]  FC(size\_t \**entries*);F\[0\]

FCsg\_user\_stats \***sg\_get\_user\_stats\_r**F\[0\]  FC(size\_t \**entries*);F\[0\]

FCsg\_error **sg\_free\_user\_stats**F\[0\]  FC(sg\_user\_stats \**data*);F\[0\]

## DESCRIPTION

The user statistics module delivers some information about logged on users. Each logon is treated separately. Both statistic get functions, FC**sg\_get\_user\_stats**F\[0\]() and FC**sg\_get\_user\_stats\_r**F\[0\](), return a vector of FCsg\_user\_statsF\[0\] with FCentriesF\[0\] elements.

**API Shortcut**

| | | |
| --- | --- | --- |
| function | returns | data owner |
| sg\_get\_user\_stats | FCsg\_user\_statsF\[0\] \* | libstatgrab (thread local) |
| sg\_get\_user\_stats\_r | FCsg\_user\_statsF\[0\] \* | caller |

The FCsg\_user\_statsF\[0\] vector received from FC**sg\_get\_user\_stats\_r**F\[0\]() must be freed using FC**sg\_free\_user\_stats**F\[0\]() when not needed any more. The caller is responsible for doing it.

## RETURN VALUES

The structure returned is of type FCsg\_user\_statsF\[0\].

```
FC
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;
    F[0]
```

- FClogin\_nameF\[0\]

  The username which was used to log in

- FCrecord\_idF\[0\]

  Record identifier of host database containing login information (not necessarily 0-terminated)

- FCrecord\_id\_sizeF\[0\]

  Size of the record identifier

- FCdeviceF\[0\]

  Device name (eg. "pts/0") of the tty assigned to the login session

- FChostnameF\[0\]

  (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)

- FCpidF\[0\]

  Process identifier of the process which made the entry to the logged on users database

- FClogin\_timeF\[0\]

  Timestamp (time in seconds since epoch) when the user logged on

- FCsystimeF\[0\]

  The timestamp when the above stats where collected in seconds since epoch

## SEE ALSO

[**statgrab**(3)](/statgrab/3.md)

## WEBSITE

⟨https://libstatgrab.org/⟩
