{"id":6,"date":"2016-10-15T11:16:30","date_gmt":"2017-03-30T16:16:25","guid":{"rendered":"https:\/\/lisas.de\/~adrian\/?p=1268"},"modified":"2018-10-10T15:41:01","modified_gmt":"2018-10-10T13:41:01","slug":"influence-which-pid-will-be-the-next","status":"publish","type":"post","link":"https:\/\/lisas.de\/luges\/index.php\/2016\/10\/15\/influence-which-pid-will-be-the-next\/","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 <tt>fork()<\/tt>-ing into the new process.<\/p>\n<p>The same interface (<tt>\/proc\/sys\/kernel\/ns_last_pid<\/tt>) can also be used from the command-line to influence which PID the kernel will use for the next process.<\/p>\n<pre># cat \/proc\/sys\/kernel\/ns_last_pid\n1626\n# echo -n 9999 &gt; \/proc\/sys\/kernel\/ns_last_pid\n# cat \/proc\/sys\/kernel\/ns_last_pid\n10000\n<\/pre>\n<p>Writing &#8216;9999&#8217; (without a &#8216;new line&#8217;) to <tt>\/proc\/sys\/kernel\/ns_last_pid<\/tt> tells the kernel, that the next PID should be &#8216;10000&#8217;. This only works if between after writing to <tt>\/proc\/sys\/kernel\/ns_last_pid<\/tt> 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":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,1],"tags":[],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-luges","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts\/6","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=6"}],"version-history":[{"count":1,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":16,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/posts\/6\/revisions\/16"}],"wp:attachment":[{"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lisas.de\/luges\/index.php\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}