1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 This file is part of systemd.
8 Copyright 2010 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id="sd_pid_get_session">
27 <title>sd_pid_get_session</title>
28 <productname>systemd</productname>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
41 <refentrytitle>sd_pid_get_session</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_pid_get_session</refname>
47 <refname>sd_pid_get_owner_uid</refname>
48 <refpurpose>Determine session or owner of a session of a specific PID</refpurpose>
53 <funcsynopsisinfo>#include <systemd/sd-login.h></funcsynopsisinfo>
56 <funcdef>int <function>sd_pid_get_session</function></funcdef>
57 <paramdef>pid_t <parameter>pid</parameter></paramdef>
58 <paramdef>char** <parameter>session</parameter></paramdef>
62 <funcdef>int <function>sd_pid_get_owner_uid</function></funcdef>
63 <paramdef>pid_t <parameter>pid</parameter></paramdef>
64 <paramdef>uid_t* <parameter>uid</parameter></paramdef>
70 <title>Description</title>
72 <para><function>sd_pid_get_session()</function> may be
73 used to determine the login session identifier of a
74 process identified by the specified process identifier. The session
75 identifier is a short string (up to 64 characters),
76 consisting only of the characters a-zA-Z0-9 as well as
77 '-' and '_'. It is suitable for usage in file system
78 paths. Note that not all processes are part of a login
79 session (e.g. system service processes and user
80 processes that are shared between multiple sessions of
81 the same user). For processes not being part of a
82 login session this function will fail. The returned
83 string needs to be freed with the libc
84 <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
85 call after use.</para>
87 <para><function>sd_pid_get_owner_uid()</function> may
88 be used to determine the Unix user identifier of the
89 owner of the session of a process identified the
90 specified PID. Note that this function will succeed
91 for user processes which are shared between multiple
92 login sessions of the same user, where
93 <function>sd_pid_get_session()</function> will
94 fail. For processes not being part of a login session
95 and not being a shared process of a user this function
100 <title>Return Value</title>
102 <para>On success these calls return 0 or a positive
103 integer. On failure, these calls return a negative
104 errno-style error code.</para>
110 <para>The <function>sd_pid_get_session()</function>
111 and <function>sd_pid_get_owner_uid()</function>
112 interfaces are available as shared library, which can
113 be compiled and linked to with the
114 <literal>libsystemd-login</literal>
115 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
118 <para>Note that the login session identifier as
119 returned by <function>sd_pid_get_session()</function>
120 is completely unrelated to the process session
121 identifier as returned by
122 <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>.</para>
126 <title>See Also</title>
129 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
130 <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
131 <citerefentry><refentrytitle>sd_session_is_active</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
132 <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>