]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_pid_get_session</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style> |
2 | a.headerlink { | |
3 | color: #c60f0f; | |
4 | font-size: 0.8em; | |
5 | padding: 0 4px 0 4px; | |
6 | text-decoration: none; | |
7 | visibility: hidden; | |
8 | } | |
9 | ||
10 | a.headerlink:hover { | |
11 | background-color: #c60f0f; | |
12 | color: white; | |
13 | } | |
14 | ||
15 | h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink { | |
16 | visibility: visible; | |
17 | } | |
18 | </style><a href="index.html">Index </a>· | |
19 | <a href="systemd.directives.html">Directives </a>· | |
20 | <a href="../python-systemd/index.html">Python </a>· | |
21 | <a href="../libudev/index.html">libudev </a>· | |
e735f4d4 MP |
22 | <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 219</span><hr><div class="refentry"><a name="sd_pid_get_session"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_pid_get_session, sd_pid_get_unit, sd_pid_get_user_unit, sd_pid_get_owner_uid, sd_pid_get_machine_name, sd_pid_get_slice, sd_peer_get_session, sd_peer_get_unit, sd_peer_get_user_unit, sd_peer_get_owner_uid, sd_peer_get_machine_name, sd_peer_get_slice — Determine session, service, owner of a |
23 | session, container/VM or slice of a specific | |
24 | PID or socket peer</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <systemd/sd-login.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_pid_get_session</b>(</code></td><td>pid_t <var class="pdparam">pid</var>, </td></tr><tr><td> </td><td>char **<var class="pdparam">session</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_pid_get_unit</b>(</code></td><td>pid_t <var class="pdparam">pid</var>, </td></tr><tr><td> </td><td>char **<var class="pdparam">unit</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_pid_get_user_unit</b>(</code></td><td>pid_t <var class="pdparam">pid</var>, </td></tr><tr><td> </td><td>char **<var class="pdparam">unit</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_pid_get_owner_uid</b>(</code></td><td>pid_t <var class="pdparam">pid</var>, </td></tr><tr><td> </td><td>uid_t *<var class="pdparam">uid</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_pid_get_machine_name</b>(</code></td><td>pid_t <var class="pdparam">pid</var>, </td></tr><tr><td> </td><td>char **<var class="pdparam">name</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_pid_get_slice</b>(</code></td><td>pid_t <var class="pdparam">pid</var>, </td></tr><tr><td> </td><td>char **<var class="pdparam">slice</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_peer_get_session</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>char **<var class="pdparam">session</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_peer_get_unit</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>char **<var class="pdparam">unit</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_peer_get_user_unit</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>char **<var class="pdparam">unit</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_peer_get_owner_uid</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>uid_t *<var class="pdparam">uid</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_peer_get_machine_name</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>char **<var class="pdparam">name</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_peer_get_slice</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>char **<var class="pdparam">slice</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm139799154390592"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description">¶</a></h2><p><code class="function">sd_pid_get_session()</code> may be used to | |
25 | determine the login session identifier of a process identified by | |
26 | the specified process identifier. The session identifier is a | |
27 | short string, suitable for usage in file system paths. Note that | |
28 | not all processes are part of a login session (e.g. system service | |
29 | processes, user processes that are shared between multiple | |
30 | sessions of the same user, or kernel threads). For processes not | |
31 | being part of a login session this function will fail. The | |
32 | returned string needs to be freed with the libc | |
33 | <a href="http://man7.org/linux/man-pages/man3/free.3.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a> | |
34 | call after use.</p><p><code class="function">sd_pid_get_unit()</code> may be used to | |
35 | determine the systemd system unit (i.e. system service) identifier | |
36 | of a process identified by the specified PID. The unit name is a | |
37 | short string, suitable for usage in file system paths. Note that | |
38 | not all processes are part of a system unit/service (e.g. user | |
39 | processes, or kernel threads). For processes not being part of a | |
40 | systemd system unit this function will fail. (More specifically: | |
41 | this call will not work for processes that are part of user units, | |
42 | use <code class="function">sd_pid_get_user_unit()</code> for that.) The | |
43 | returned string needs to be freed with the libc | |
44 | <a href="http://man7.org/linux/man-pages/man3/free.3.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a> | |
45 | call after use.</p><p><code class="function">sd_pid_get_user_unit()</code> may be used to | |
46 | determine the systemd user unit (i.e. user service) identifier of | |
47 | a process identified by the specified PID. This is similar to | |
48 | <code class="function">sd_pid_get_unit()</code> but applies to user units | |
49 | instead of system units.</p><p><code class="function">sd_pid_get_owner_uid()</code> may be used to | |
50 | determine the Unix user identifier of the owner of the session of | |
51 | a process identified the specified PID. Note that this function | |
52 | will succeed for user processes which are shared between multiple | |
53 | login sessions of the same user, where | |
54 | <code class="function">sd_pid_get_session()</code> will fail. For processes | |
55 | not being part of a login session and not being a shared process | |
56 | of a user this function will fail.</p><p><code class="function">sd_pid_get_machine_name()</code> may be used | |
57 | to determine the name of the VM or container is a member of. The | |
58 | machine name is a short string, suitable for usage in file system | |
59 | paths. The returned string needs to be freed with the libc | |
60 | <a href="http://man7.org/linux/man-pages/man3/free.3.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a> | |
61 | call after use.</p><p><code class="function">sd_pid_get_slice()</code> may be used to | |
62 | determine the slice unit the process is a member of. See | |
63 | <a href="systemd.slice.html"><span class="citerefentry"><span class="refentrytitle">systemd.slice</span>(5)</span></a> | |
64 | for details about slices. The returned string needs to be freed | |
65 | with the libc | |
66 | <a href="http://man7.org/linux/man-pages/man3/free.3.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a> | |
67 | call after use.</p><p>If the <code class="varname">pid</code> parameter of any of these | |
68 | functions is passed as 0, the operation is executed for the | |
69 | calling process.</p><p>The <code class="function">sd_peer_get_session()</code>, | |
70 | <code class="function">sd_peer_get_unit()</code>, | |
71 | <code class="function">sd_peer_get_user_unit()</code>, | |
72 | <code class="function">sd_peer_get_owner_uid()</code>, | |
73 | <code class="function">sd_peer_get_machine_name()</code> and | |
74 | <code class="function">sd_peer_get_slice()</code> calls operate similar to | |
75 | their PID counterparts, but operate on a connected AF_UNIX socket | |
76 | and retrieve information about the connected peer process.</p></div><div class="refsect1"><a name="idm139799149455248"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value">¶</a></h2><p>On success, these calls return 0 or a positive integer. On | |
77 | failure, these calls return a negative errno-style error | |
78 | code.</p></div><div class="refsect1"><a name="idm139799149453952"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes">¶</a></h2><p>The <code class="function">sd_pid_get_session()</code>, | |
79 | <code class="function">sd_pid_get_unit()</code>, | |
80 | <code class="function">sd_pid_get_user_unit()</code>, | |
81 | <code class="function">sd_pid_get_owner_uid()</code>, | |
82 | <code class="function">sd_pid_get_machine_name()</code>, | |
83 | <code class="function">sd_pid_get_slice()</code>, | |
84 | <code class="function">sd_peer_get_session()</code>, | |
85 | <code class="function">sd_peer_get_unit()</code>, | |
86 | <code class="function">sd_peer_get_user_unit()</code>, | |
87 | <code class="function">sd_peer_get_owner_uid()</code>, | |
88 | <code class="function">sd_peer_get_machine_name()</code> and | |
89 | <code class="function">sd_peer_get_slice()</code> interfaces are | |
90 | available as a shared library, which can be compiled | |
91 | and linked to with the | |
92 | <code class="constant">libsystemd</code> <a href="http://linux.die.net/man/1/pkg-config"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a> | |
93 | file.</p><p>Note that the login session identifier as | |
94 | returned by <code class="function">sd_pid_get_session()</code> | |
95 | is completely unrelated to the process session | |
96 | identifier as returned by | |
97 | <a href="http://man7.org/linux/man-pages/man2/getsid.2.html"><span class="citerefentry"><span class="refentrytitle">getsid</span>(2)</span></a>.</p></div><div class="refsect1"><a name="idm139799149442016"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p> | |
98 | <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>, | |
99 | <a href="sd-login.html"><span class="citerefentry"><span class="refentrytitle">sd-login</span>(3)</span></a>, | |
100 | <a href="sd_session_is_active.html"><span class="citerefentry"><span class="refentrytitle">sd_session_is_active</span>(3)</span></a>, | |
101 | <a href="http://man7.org/linux/man-pages/man2/getsid.2.html"><span class="citerefentry"><span class="refentrytitle">getsid</span>(2)</span></a>, | |
102 | <a href="systemd.slice.html"><span class="citerefentry"><span class="refentrytitle">systemd.slice</span>(5)</span></a>, | |
103 | <a href="systemd-machined.service.html"><span class="citerefentry"><span class="refentrytitle">systemd-machined.service</span>(8)</span></a> | |
104 | </p></div></div></body></html> |