]>
Commit | Line | Data |
---|---|---|
60f067b4 JS |
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>· | |
f47781d8 | 22 | <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 218</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 |
60f067b4 | 23 | session, container/VM or slice of a specific |
f47781d8 | 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="idm139886821813536"></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 |
60f067b4 JS |
25 | used to determine the login session identifier of a |
26 | process identified by the specified process | |
27 | identifier. The session identifier is a short string, | |
28 | suitable for usage in file system paths. Note that not | |
29 | all processes are part of a login session (e.g. system | |
30 | service processes, user processes that are shared | |
31 | between multiple sessions of the same user, or kernel | |
32 | threads). For processes not being part of a login | |
33 | session this function will fail. The returned string | |
34 | needs to be freed with the libc | |
5eef597e | 35 | <a href="http://man7.org/linux/man-pages/man3/free.3.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a> |
60f067b4 JS |
36 | call after use.</p><p><code class="function">sd_pid_get_unit()</code> may be |
37 | used to determine the systemd system unit (i.e. system | |
38 | service) identifier of a process identified by the | |
39 | specified PID. The unit name is a short string, | |
40 | suitable for usage in file system paths. Note that not | |
41 | all processes are part of a system unit/service | |
42 | (e.g. user processes, or kernel threads). For | |
43 | processes not being part of a systemd system unit this | |
44 | function will fail. (More specifically: this call will | |
45 | not work for processes that are part of user units, | |
46 | use <code class="function">sd_pid_get_user_unit()</code> for | |
47 | that.) The returned string needs to be freed with the | |
48 | libc | |
5eef597e | 49 | <a href="http://man7.org/linux/man-pages/man3/free.3.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a> |
60f067b4 JS |
50 | call after use.</p><p><code class="function">sd_pid_get_user_unit()</code> may |
51 | be used to determine the systemd user unit (i.e. user | |
52 | service) identifier of a process identified by the | |
53 | specified PID. This is similar to | |
54 | <code class="function">sd_pid_get_unit()</code> but applies to | |
55 | user units instead of system units.</p><p><code class="function">sd_pid_get_owner_uid()</code> may | |
56 | be used to determine the Unix user identifier of the | |
57 | owner of the session of a process identified the | |
58 | specified PID. Note that this function will succeed | |
59 | for user processes which are shared between multiple | |
60 | login sessions of the same user, where | |
61 | <code class="function">sd_pid_get_session()</code> will | |
62 | fail. For processes not being part of a login session | |
63 | and not being a shared process of a user this function | |
64 | will fail.</p><p><code class="function">sd_pid_get_machine_name()</code> | |
65 | may be used to determine the name of the VM or | |
66 | container is a member of. The machine name is a short | |
67 | string, suitable for usage in file system paths. The | |
68 | returned string needs to be freed with the libc | |
5eef597e | 69 | <a href="http://man7.org/linux/man-pages/man3/free.3.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a> |
60f067b4 JS |
70 | call after use.</p><p><code class="function">sd_pid_get_slice()</code> may be |
71 | used to determine the slice unit the process is a | |
72 | member of. See | |
73 | <a href="systemd.slice.html"><span class="citerefentry"><span class="refentrytitle">systemd.slice</span>(5)</span></a> | |
74 | for details about slices. The returned string needs to | |
75 | be freed with the libc | |
5eef597e | 76 | <a href="http://man7.org/linux/man-pages/man3/free.3.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a> |
60f067b4 JS |
77 | call after use.</p><p>If the <code class="varname">pid</code> parameter of any |
78 | of these functions is passed as 0, the operation is | |
79 | executed for the calling process.</p><p>The <code class="function">sd_peer_get_session()</code>, | |
80 | <code class="function">sd_peer_get_unit()</code>, | |
81 | <code class="function">sd_peer_get_user_unit()</code>, | |
82 | <code class="function">sd_peer_get_owner_uid()</code>, | |
83 | <code class="function">sd_peer_get_machine_name()</code> and | |
84 | <code class="function">sd_peer_get_slice()</code> calls operate | |
85 | similar to their PID counterparts, but operate on a | |
86 | connected AF_UNIX socket and retrieve information | |
f47781d8 | 87 | about the connected peer process.</p></div><div class="refsect1"><a name="idm139886817113888"></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 |
60f067b4 | 88 | integer. On failure, these calls return a negative |
f47781d8 | 89 | errno-style error code.</p></div><div class="refsect1"><a name="idm139886817112560"></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>, |
60f067b4 JS |
90 | <code class="function">sd_pid_get_unit()</code>, |
91 | <code class="function">sd_pid_get_user_unit()</code>, | |
92 | <code class="function">sd_pid_get_owner_uid()</code>, | |
93 | <code class="function">sd_pid_get_machine_name()</code>, | |
94 | <code class="function">sd_pid_get_slice()</code>, | |
95 | <code class="function">sd_peer_get_session()</code>, | |
96 | <code class="function">sd_peer_get_unit()</code>, | |
97 | <code class="function">sd_peer_get_user_unit()</code>, | |
98 | <code class="function">sd_peer_get_owner_uid()</code>, | |
99 | <code class="function">sd_peer_get_machine_name()</code> and | |
100 | <code class="function">sd_peer_get_slice()</code> interfaces are | |
101 | available as a shared library, which can be compiled | |
102 | and linked to with the | |
5eef597e | 103 | <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> |
60f067b4 JS |
104 | file.</p><p>Note that the login session identifier as |
105 | returned by <code class="function">sd_pid_get_session()</code> | |
106 | is completely unrelated to the process session | |
107 | identifier as returned by | |
f47781d8 | 108 | <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="idm139886817100448"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p> |
60f067b4 JS |
109 | <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>, |
110 | <a href="sd-login.html"><span class="citerefentry"><span class="refentrytitle">sd-login</span>(3)</span></a>, | |
111 | <a href="sd_session_is_active.html"><span class="citerefentry"><span class="refentrytitle">sd_session_is_active</span>(3)</span></a>, | |
5eef597e MP |
112 | <a href="http://man7.org/linux/man-pages/man2/getsid.2.html"><span class="citerefentry"><span class="refentrytitle">getsid</span>(2)</span></a>, |
113 | <a href="systemd.slice.html"><span class="citerefentry"><span class="refentrytitle">systemd.slice</span>(5)</span></a>, | |
114 | <a href="systemd-machined.service.html"><span class="citerefentry"><span class="refentrytitle">systemd-machined.service</span>(8)</span></a> | |
60f067b4 | 115 | </p></div></div></body></html> |