]>
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>· | |
22 | <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 204</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 — Determine session, service, owner of a session or container/VM of a specific PID</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></div></div><div class="refsect1"><a name="idm259781218496"></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 | |
23 | used to determine the login session identifier of a | |
24 | process identified by the specified process | |
25 | identifier. The session identifier is a short string, | |
26 | suitable for usage in file system paths. Note that not | |
27 | all processes are part of a login session (e.g. system | |
28 | service processes, user processes that are shared | |
29 | between multiple sessions of the same user, or kernel | |
30 | threads). For processes not being part of a login | |
31 | session this function will fail. The returned string | |
32 | needs to be freed with the libc | |
33 | <a href="free.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 | |
35 | used to determine the systemd system unit (i.e. system | |
36 | service) identifier of a process identified by the | |
37 | specified PID. The unit name is a short string, | |
38 | suitable for usage in file system paths. Note that not | |
39 | all processes are part of a system unit/service | |
40 | (e.g. user processes, or kernel threads). For | |
41 | processes not being part of a systemd system unit this | |
42 | function will fail. (More specifically: this call will | |
43 | not work for processes that are part of user units, | |
44 | use <code class="function">sd_pid_get_user_unit()</code> for | |
45 | that.) The returned string needs to be freed with the | |
46 | libc | |
47 | <a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a> | |
48 | call after use.</p><p><code class="function">sd_pid_get_user_unit()</code> may | |
49 | be used to determine the systemd user unit (i.e. user | |
50 | service) identifier of a process identified by the | |
51 | specified PID. This is similar to | |
52 | <code class="function">sd_pid_get_unit()</code> but applies to | |
53 | user units instead of system units.</p><p><code class="function">sd_pid_get_owner_uid()</code> may | |
54 | be used to determine the Unix user identifier of the | |
55 | owner of the session of a process identified the | |
56 | specified PID. Note that this function will succeed | |
57 | for user processes which are shared between multiple | |
58 | login sessions of the same user, where | |
59 | <code class="function">sd_pid_get_session()</code> will | |
60 | fail. For processes not being part of a login session | |
61 | and not being a shared process of a user this function | |
62 | will fail.</p><p><code class="function">sd_pid_machine_name()</code> may | |
63 | be used to determine the name of the VM or container | |
64 | is a member of. The machine name is a short string, | |
65 | suitable for usage in file system paths. The returned | |
66 | string needs to be freed with the libc | |
67 | <a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a> | |
68 | call after use.</p><p>If the <code class="literal">pid</code> parameter of any | |
69 | of these functions is passed as 0 the operation is | |
70 | executed for the calling process.</p></div><div class="refsect1"><a name="idm259785104832"></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 | |
71 | integer. On failure, these calls return a negative | |
72 | errno-style error code.</p></div><div class="refsect1"><a name="idm259785103472"></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>, | |
73 | <code class="function">sd_pid_get_unit()</code>, | |
74 | <code class="function">sd_pid_get_user_unit()</code>, | |
75 | <code class="function">sd_pid_get_owner_uid()</code> and | |
76 | <code class="function">sd_pid_get_machine_name()</code> | |
77 | interfaces are available as shared library, which can | |
78 | be compiled and linked to with the | |
79 | <code class="literal">libsystemd-login</code> | |
80 | <a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a> | |
81 | file.</p><p>Note that the login session identifier as | |
82 | returned by <code class="function">sd_pid_get_session()</code> | |
83 | is completely unrelated to the process session | |
84 | identifier as returned by | |
85 | <a href="getsid.html"><span class="citerefentry"><span class="refentrytitle">getsid</span>(2)</span></a>.</p></div><div class="refsect1"><a name="idm259785087648"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p> | |
86 | <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>, | |
87 | <a href="sd-login.html"><span class="citerefentry"><span class="refentrytitle">sd-login</span>(3)</span></a>, | |
88 | <a href="sd_session_is_active.html"><span class="citerefentry"><span class="refentrytitle">sd_session_is_active</span>(3)</span></a>, | |
89 | <a href="getsid.html"><span class="citerefentry"><span class="refentrytitle">getsid</span>(2)</span></a> | |
90 | </p></div></div></body></html> |