1SD_PID_GET_SESSION(3)         sd_pid_get_session         SD_PID_GET_SESSION(3)
2
3
4

NAME

6       sd_pid_get_session, sd_pid_get_unit, sd_pid_get_user_unit,
7       sd_pid_get_owner_uid, sd_pid_get_machine_name, sd_pid_get_slice,
8       sd_peer_get_session, sd_peer_get_unit, sd_peer_get_user_unit,
9       sd_peer_get_owner_uid, sd_peer_get_machine_name, sd_peer_get_slice -
10       Determine session, service, owner of a session, container/VM or slice
11       of a specific PID or socket peer
12

SYNOPSIS

14       #include <systemd/sd-login.h>
15
16       int sd_pid_get_session(pid_t pid, char **session);
17
18       int sd_pid_get_unit(pid_t pid, char **unit);
19
20       int sd_pid_get_user_unit(pid_t pid, char **unit);
21
22       int sd_pid_get_owner_uid(pid_t pid, uid_t *uid);
23
24       int sd_pid_get_machine_name(pid_t pid, char **name);
25
26       int sd_pid_get_slice(pid_t pid, char **slice);
27
28       int sd_peer_get_session(int fd, char **session);
29
30       int sd_peer_get_unit(int fd, char **unit);
31
32       int sd_peer_get_user_unit(int fd, char **unit);
33
34       int sd_peer_get_owner_uid(int fd, uid_t *uid);
35
36       int sd_peer_get_machine_name(int fd, char **name);
37
38       int sd_peer_get_slice(int fd, char **slice);
39

DESCRIPTION

41       sd_pid_get_session() may be used to determine the login session
42       identifier of a process identified by the specified process identifier.
43       The session identifier is a short string, suitable for usage in file
44       system paths. Note that not all processes are part of a login session
45       (e.g. system service processes, user processes that are shared between
46       multiple sessions of the same user, or kernel threads). For processes
47       not being part of a login session this function will fail. The returned
48       string needs to be freed with the libc free(3) call after use.
49
50       sd_pid_get_unit() may be used to determine the systemd system unit
51       (i.e. system service) identifier of a process identified by the
52       specified PID. The unit name is a short string, suitable for usage in
53       file system paths. Note that not all processes are part of a system
54       unit/service (e.g. user processes, or kernel threads). For processes
55       not being part of a systemd system unit this function will fail. (More
56       specifically: this call will not work for processes that are part of
57       user units, use sd_pid_get_user_unit() for that.) The returned string
58       needs to be freed with the libc free(3) call after use.
59
60       sd_pid_get_user_unit() may be used to determine the systemd user unit
61       (i.e. user service) identifier of a process identified by the specified
62       PID. This is similar to sd_pid_get_unit() but applies to user units
63       instead of system units.
64
65       sd_pid_get_owner_uid() may be used to determine the Unix user
66       identifier of the owner of the session of a process identified the
67       specified PID. Note that this function will succeed for user processes
68       which are shared between multiple login sessions of the same user,
69       where sd_pid_get_session() will fail. For processes not being part of a
70       login session and not being a shared process of a user this function
71       will fail.
72
73       sd_pid_get_machine_name() may be used to determine the name of the VM
74       or container is a member of. The machine name is a short string,
75       suitable for usage in file system paths. The returned string needs to
76       be freed with the libc free(3) call after use.
77
78       sd_pid_get_slice() may be used to determine the slice unit the process
79       is a member of. See systemd.slice(5) for details about slices. The
80       returned string needs to be freed with the libc free(3) call after use.
81
82       If the pid parameter of any of these functions is passed as 0, the
83       operation is executed for the calling process.
84
85       The sd_peer_get_session(), sd_peer_get_unit(), sd_peer_get_user_unit(),
86       sd_peer_get_owner_uid(), sd_peer_get_machine_name() and
87       sd_peer_get_slice() calls operate similar to their PID counterparts,
88       but operate on a connected AF_UNIX socket and retrieve information
89       about the connected peer process.
90

RETURN VALUE

92       On success, these calls return 0 or a positive integer. On failure,
93       these calls return a negative errno-style error code.
94

NOTES

96       The sd_pid_get_session(), sd_pid_get_unit(), sd_pid_get_user_unit(),
97       sd_pid_get_owner_uid(), sd_pid_get_machine_name(), sd_pid_get_slice(),
98       sd_peer_get_session(), sd_peer_get_unit(), sd_peer_get_user_unit(),
99       sd_peer_get_owner_uid(), sd_peer_get_machine_name() and
100       sd_peer_get_slice() interfaces are available as a shared library, which
101       can be compiled and linked to with the libsystemd pkg-config(1) file.
102
103       Note that the login session identifier as returned by
104       sd_pid_get_session() is completely unrelated to the process session
105       identifier as returned by getsid(2).
106

SEE ALSO

108       systemd(1), sd-login(3), sd_session_is_active(3), getsid(2),
109       systemd.slice(5), systemd-machined.service(8)
110
111
112
113systemd 219                                              SD_PID_GET_SESSION(3)
Impressum