sd_pid_get_session.xml revision 0b3b020a178cf3b957fed627de13c895773995ec
402N/A<?xml version='1.0'?> <!--*-nxml-*-->
402N/A<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
402N/A "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
402N/A
402N/A<!--
402N/A This file is part of systemd.
402N/A
402N/A Copyright 2010 Lennart Poettering
402N/A
402N/A systemd is free software; you can redistribute it and/or modify it
402N/A under the terms of the GNU General Public License as published by
402N/A the Free Software Foundation; either version 2 of the License, or
402N/A (at your option) any later version.
402N/A
402N/A systemd is distributed in the hope that it will be useful, but
402N/A WITHOUT ANY WARRANTY; without even the implied warranty of
402N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
402N/A General Public License for more details.
402N/A
402N/A You should have received a copy of the GNU General Public License
3817N/A along with systemd; If not, see <http://www.gnu.org/licenses/>.
402N/A-->
814N/A
814N/A<refentry id="sd_pid_get_session">
814N/A
1780N/A <refentryinfo>
814N/A <title>sd_pid_get_session</title>
402N/A <productname>systemd</productname>
402N/A
402N/A <authorgroup>
402N/A <author>
402N/A <contrib>Developer</contrib>
402N/A <firstname>Lennart</firstname>
618N/A <surname>Poettering</surname>
402N/A <email>lennart@poettering.net</email>
402N/A </author>
402N/A </authorgroup>
844N/A </refentryinfo>
844N/A
402N/A <refmeta>
1407N/A <refentrytitle>sd_pid_get_session</refentrytitle>
402N/A <manvolnum>3</manvolnum>
2899N/A </refmeta>
2899N/A
4250N/A <refnamediv>
814N/A <refname>sd_pid_get_session</refname>
3817N/A <refname>sd_pid_get_owner_uid</refname>
3817N/A <refpurpose>Determine session or owner of a session of a specific PID</refpurpose>
3817N/A </refnamediv>
402N/A
3955N/A <refsynopsisdiv>
3955N/A <funcsynopsis>
3955N/A <funcsynopsisinfo>#include &lt;systemd/sd-login.h&gt;</funcsynopsisinfo>
3955N/A
3955N/A <funcprototype>
3955N/A <funcdef>int <function>sd_pid_get_session</function></funcdef>
3955N/A <paramdef>pid_t <parameter>pid</parameter></paramdef>
3955N/A <paramdef>char** <parameter>session</parameter></paramdef>
3955N/A </funcprototype>
3955N/A
3955N/A <funcprototype>
3955N/A <funcdef>int <function>sd_pid_get_owner_uid</function></funcdef>
3955N/A <paramdef>pid_t <parameter>pid</parameter></paramdef>
3955N/A <paramdef>uid_t* <parameter>uid</parameter></paramdef>
402N/A </funcprototype>
402N/A </funcsynopsis>
402N/A </refsynopsisdiv>
402N/A
402N/A <refsect1>
402N/A <title>Description</title>
402N/A
402N/A <para><function>sd_pid_get_session()</function> may be
402N/A used to determine the login session identifier of a
402N/A process identified by the specified process identifier. The session
402N/A identifier is a short string (up to 64 characters),
402N/A consisting only of the characters a-zA-Z0-9 as well as
402N/A '-' and '_'. It is suitable for usage in file system
402N/A paths. Note that not all processes are part of a login
402N/A session (e.g. system service processes and user
402N/A processes that are shared between multiple sessions of
402N/A the same user). For processes not being part of a
402N/A login session this function will fail. The returned
402N/A string needs to be freed with the libc
402N/A <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
402N/A call after use.</para>
402N/A
402N/A <para><function>sd_pid_get_owner_uid()</function> may
402N/A be used to determine the Unix user identifier of the
402N/A owner of the session of a process identified the
402N/A specified PID. Note that this function will succeed
402N/A for user processes which are shared between multiple
402N/A login sessions of the same user, where
402N/A <function>sd_pid_get_session()</function> will
402N/A fail. For processes not being part of a login session
402N/A and not being a shared process of a user this function
402N/A will fail.</para>
402N/A </refsect1>
402N/A
402N/A <refsect1>
402N/A <title>Return Value</title>
402N/A
402N/A <para>On success these calls return 0 or a positive
402N/A integer. On failure, these calls return a negative
402N/A errno-style error code.</para>
402N/A </refsect1>
402N/A
459N/A <refsect1>
402N/A <title>Notes</title>
402N/A
402N/A <para>The <function>sd_pid_get_session()</function>
402N/A and <function>sd_pid_get_owner_uid()</function>
402N/A interfaces are available as shared library, which can
402N/A be compiled and linked to with the
402N/A <literal>libsystemd-login</literal>
402N/A <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
402N/A file.</para>
402N/A
402N/A <para>Note that the login session identifier as
402N/A returned by <function>sd_pid_get_session()</function>
402N/A is completely unrelated to the process session
402N/A identifier as returned by
402N/A <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>.</para>
402N/A </refsect1>
402N/A
402N/A <refsect1>
402N/A <title>See Also</title>
402N/A
402N/A <para>
402N/A <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
402N/A <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
4496N/A <citerefentry><refentrytitle>sd_session_is_active</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
402N/A <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>
402N/A </para>
3955N/A </refsect1>
402N/A
402N/A</refentry>
402N/A