<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://criu.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bsach64</id>
	<title>CRIU - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://criu.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bsach64"/>
	<link rel="alternate" type="text/html" href="https://criu.org/Special:Contributions/Bsach64"/>
	<updated>2026-05-13T18:42:08Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.6</generator>
	<entry>
		<id>https://criu.org/index.php?title=Pidfd&amp;diff=5580</id>
		<title>Pidfd</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=Pidfd&amp;diff=5580"/>
		<updated>2025-01-04T18:52:55Z</updated>

		<summary type="html">&lt;p&gt;Bsach64: &lt;/p&gt;
&lt;hr /&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;br /&gt;
&lt;br /&gt;
[[Category:Under the hood]]&lt;/div&gt;</summary>
		<author><name>Bsach64</name></author>
	</entry>
	<entry>
		<id>https://criu.org/index.php?title=Pidfd&amp;diff=5579</id>
		<title>Pidfd</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=Pidfd&amp;diff=5579"/>
		<updated>2025-01-04T18:52:06Z</updated>

		<summary type="html">&lt;p&gt;Bsach64: 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;hr /&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>