{"id":616,"date":"2016-10-15T11:16:00","date_gmt":"2016-10-15T09:16:00","guid":{"rendered":"https:\/\/lisas.de\/~adrian\/posts\/2016-Oct-15-influence-which-pid-will-be-the-next.html"},"modified":"2026-03-30T22:41:24","modified_gmt":"2026-03-30T20:41:24","slug":"influence-which-pid-will-be-the-next-2","status":"publish","type":"post","link":"https:\/\/lisas.de\/luges\/index.php\/2016\/10\/15\/influence-which-pid-will-be-the-next-2\/","title":{"rendered":"Influence which PID will be the next"},"content":{"rendered":"<p>To restore a checkpointed process with <a href=\"https:\/\/criu.org\/\">CRIU<\/a> the process ID (PID) has to be the same it was during checkpointing. <em>CRIU<\/em> uses <a href=\"https:\/\/git.kernel.org\/cgit\/linux\/kernel\/git\/torvalds\/linux.git\/commit\/?id=b8f566b04d3cddd192cfd2418ae6d54ac6353792\">\/proc\/sys\/kernel\/ns_last_pid<\/a> to set the PID to one lower as the process to be restored just before <code>fork()<\/code>-ing into the new process.<\/p>\n<p>The same interface (<code>\/proc\/sys\/kernel\/ns_last_pid<\/code>) can also be used from the command-line to influence which PID the kernel will use for the next process.<\/p>\n<div class=\"highlight\">\n<pre><span><\/span><code><span class=\"gh\">#<\/span> cat \/proc\/sys\/kernel\/ns_last_pid 1626 <span class=\"gh\">#<\/span> echo -n 9999 &gt; \/proc\/sys\/kernel\/ns_last_pid <span class=\"gh\">#<\/span> cat \/proc\/sys\/kernel\/ns_last_pid 10000 <\/code><\/pre>\n<\/div>\n<p>Writing &#8216;9999&#8217; (without a &#8216;new line&#8217;) to <code>\/proc\/sys\/kernel\/ns_last_pid<\/code> tells the kernel, that the next PID should be &#8216;10000&#8217;. This only works if between after writing to <code>\/proc\/sys\/kernel\/ns_last_pid<\/code> and forking the new process no other process has been created. So it is not possible to guarantee which PID the new process will get but it can be influenced.<\/p>\n<p>There is also a posting which describes how to do the same with C: <a href=\"http:\/\/efiop-notes.blogspot.de\/2014\/06\/how-to-set-pid-using-nslastpid.html\">How to set PID using ns_last_pid<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To restore a checkpointed process with CRIU the process ID (PID) has to be the same it was during checkpointing. CRIU uses \/proc\/sys\/kernel\/ns_last_pid to set the PID to one lower as the process to be restored just before fork()-ing into the new process. The same interface (\/proc\/sys\/kernel\/ns_last_pid) can also be used from the command-line to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-616","post","type-post","status-publish","format-standard","hentry","category-luges"],"_links":{"self":[{"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts\/616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/comments?post=616"}],"version-history":[{"count":6,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts\/616\/revisions"}],"predecessor-version":[{"id":1993,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts\/616\/revisions\/1993"}],"wp:attachment":[{"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/media?parent=616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/categories?post=616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/tags?post=616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}