<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://criu.org/index.php?action=history&amp;feed=atom&amp;title=Pidfd</id>
	<title>Pidfd - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://criu.org/index.php?action=history&amp;feed=atom&amp;title=Pidfd"/>
	<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=Pidfd&amp;action=history"/>
	<updated>2026-05-13T19:02:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.6</generator>
	<entry>
		<id>https://criu.org/index.php?title=Pidfd&amp;diff=5580&amp;oldid=prev</id>
		<title>Bsach64 at 18:52, 4 January 2025</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=Pidfd&amp;diff=5580&amp;oldid=prev"/>
		<updated>2025-01-04T18:52:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:52, 4 January 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l35&quot; &gt;Line 35:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 35:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* We currently do not support pidfd's opened with the &amp;lt;code&amp;gt;PIDFD_THREAD&amp;lt;/code&amp;gt; flag.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* We currently do not support pidfd's opened with the &amp;lt;code&amp;gt;PIDFD_THREAD&amp;lt;/code&amp;gt; flag.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* We also cannot C/R pidfd's that point to process(es) outside the current process tree.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* We also cannot C/R pidfd's that point to process(es) outside the current process tree.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Under the hood]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Bsach64</name></author>
	</entry>
	<entry>
		<id>https://criu.org/index.php?title=Pidfd&amp;diff=5579&amp;oldid=prev</id>
		<title>Bsach64: Created page with &quot;This article describes how we checkpoint/restore pidfds (process file descriptors).  == Checkpointing == All information that we require for restore of pidfds is available in...&quot;</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=Pidfd&amp;diff=5579&amp;oldid=prev"/>
		<updated>2025-01-04T18:52:06Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This article describes how we checkpoint/restore pidfds (process file descriptors).  == Checkpointing == All information that we require for restore of pidfds is available in...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This article describes how we checkpoint/restore pidfds (process file descriptors).&lt;br /&gt;
&lt;br /&gt;
== Checkpointing ==&lt;br /&gt;
All information that we require for restore of pidfds is available in this &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; entry: &amp;lt;code&amp;gt;/proc/$pid/fdinfo/$pidfd&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since CRIU does not support nested pid namespaces, the correct &amp;lt;code&amp;gt;pid&amp;lt;/code&amp;gt; to use during restore is the last &amp;lt;code&amp;gt;pid&amp;lt;/code&amp;gt; (i.e., &amp;lt;code&amp;gt;pid&amp;lt;/code&amp;gt; in the most deeply nested pid namespace) in the &amp;lt;code&amp;gt;/proc/$pid/fdinfo/$pidfd/NSpid&amp;lt;/code&amp;gt; field.&lt;br /&gt;
So, we only dump that &amp;lt;code&amp;gt;pid&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Restoring &amp;lt;code&amp;gt;pidfd(s)&amp;lt;/code&amp;gt; Pointing to an Alive Process ==&lt;br /&gt;
CRIU, while restoring, first creates all processes in the process tree and then starts opening file descriptors in each process.&lt;br /&gt;
&lt;br /&gt;
So, If the pidfd points to an alive process, we can simply use &amp;lt;code&amp;gt;pidfd_open()&amp;lt;/code&amp;gt; to create the pidfd.&lt;br /&gt;
&lt;br /&gt;
== Restoring &amp;lt;code&amp;gt;pidfd(s)&amp;lt;/code&amp;gt; Pointing to a Dead Process ==&lt;br /&gt;
&lt;br /&gt;
If the process (to which the pidfd was pointing) is dead, however, we lose access to its pid (&amp;lt;code&amp;gt;/proc/$pid/fdinfo/$pidfd/NSpid&amp;lt;/code&amp;gt; becomes -1).&lt;br /&gt;
We also cannot open a pidfd pointing to a dead process.&lt;br /&gt;
&lt;br /&gt;
To overcome these problems, we do the following things:&lt;br /&gt;
&lt;br /&gt;
We create a &amp;lt;code&amp;gt;hashtable&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;inode number&amp;lt;/code&amp;gt; of the pidfd acting as the key that stores:&lt;br /&gt;
* List of all processes that had a pidfd open with this inode number.&lt;br /&gt;
* The highest id in the list of processes (&amp;lt;code&amp;gt;creator_id&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
For each unique &amp;lt;code&amp;gt;inode number&amp;lt;/code&amp;gt;, the process with &amp;lt;code&amp;gt;creator_id&amp;lt;/code&amp;gt; (let's call it &amp;lt;code&amp;gt;creator&amp;lt;/code&amp;gt;) creates a temporary process (let's name this process &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The creator process will then open &amp;lt;code&amp;gt;pidfd(s)&amp;lt;/code&amp;gt; pointing to &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; and will send them to all other processes (that had a pidfd with this inode number) using CRIU's &amp;lt;code&amp;gt;send_desc_to_peer&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;recv_desc_from_peer&amp;lt;/code&amp;gt; functions, which allow processes to send and receive file descriptors.&lt;br /&gt;
&lt;br /&gt;
This way, all processes with pidfds that point to the same dead process remain in the correct state (i.e., have pidfds with the same inode number) even after restoration.&lt;br /&gt;
&lt;br /&gt;
After the creator process finishes opening and sending all pidfds, it kills the temporary process &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Limitations ==&lt;br /&gt;
&lt;br /&gt;
* We currently do not support pidfd's opened with the &amp;lt;code&amp;gt;PIDFD_THREAD&amp;lt;/code&amp;gt; flag.&lt;br /&gt;
* We also cannot C/R pidfd's that point to process(es) outside the current process tree.&lt;/div&gt;</summary>
		<author><name>Bsach64</name></author>
	</entry>
</feed>