{"id":39723,"date":"2004-04-20T07:00:00","date_gmt":"2004-04-20T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/04\/20\/why-cant-the-system-hibernate-just-one-process\/"},"modified":"2004-04-20T07:00:00","modified_gmt":"2004-04-20T07:00:00","slug":"why-cant-the-system-hibernate-just-one-process","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040420-00\/?p=39723","title":{"rendered":"Why can&#039;t the system hibernate just one process?"},"content":{"rendered":"<p>\nWindows lets you hibernate the entire machine, but why can&#8217;t\nit hibernate just one process?  Record the state of the process\nand then resume it later.\n<\/p>\n<p>\nBecause there is state in the system that is not part of the process.\n<\/p>\n<p>\nFor example, suppose your program has taken a mutex, and then it\ngets process-hibernated.  Oops, now that mutex is abandoned\nand is now up for grabs.  If that mutex was protecting some\nstate, then when the process is resumed from hibernation,\nit thinks it still owns the mutex and the state should therefore\nbe safe from tampering, only to find that it <b>doesn&#8217;t\nown the mutex any more<\/b> and its state is corrupted.\n<\/p>\n<p>\nImagine all the code that does something like this:<\/p>\n<pre>\n\/\/ assume hmtx is a mutex handle that\n\/\/ protects some shared object G\nWaitForSingleObject(hmtx, INFINITE);\n\/\/ do stuff with G\n...\n\/\/ do more stuff with G on the assumption that\n\/\/ G hasn't changed.\nReleaseMutex(hmtx);\n<\/pre>\n<p>\nNobody expects that the mutex could secretly get released\nduring the &#8220;&#8230;&#8221; (which is what would happen if the process\ngot hibernated).  That goes against everything mutexes stand for!<\/p>\n<p><p>\nConsider, as another example, the case where you have a file\nthat was opened for exclusive access.  The program will\nhappily run on the assumption that nobody can modify\nthe file except that program.  But if you process-hibernate\nit, then some other process can now open the file (the exclusive owner\nis no longer around), tamper with it, then resume the original program.\nThe original program on resumption will see a tampered-with file and\nmay crash or (worse) be tricked into a security vulnerability.\n<\/p>\n<p>\nOne alternative would be to keep all objects that belong to\na process-hibernated program still open.  Then you would have\nthe problem of a file that can&#8217;t be deleted because it is\nbeing held open by a program that isn&#8217;t even running!\n(And indeed, for the resumption to be successful across a reboot,\nthe file would have to be re-opened upon reboot. So now you have\na file that can&#8217;t be deleted even after a reboot because it&#8217;s\nbeing held open by a program that isn&#8217;t running.  Think of the\namazing denial-of-service you could launch against somebody:\nCreate and hold open a 20GB file, then hibernate the process\nand then delete the hibernation file.\nHa-ha, you just created a permanently undeletable 20GB file.)\n<\/p>\n<p>\nNow what if the hibernated program had created windows.\nShould the window handles still be valid while the program\nis hibernated?  What happens if you send it a message?\nIf the window handles should not remain valid, then what happens\nto broadcast messages? Are they &#8220;saved somewhere&#8221; to be replayed\nwhen the program is resumed?  (And what if the broadcast message\nwas something like &#8220;I am about to remove this USB hard drive,\nhere is your last chance to flush your data&#8221;?\nThe hibernated program wouldn&#8217;t get a chance to flush its data.\nResult: Corrupted USB hard drive.)\n<\/p>\n<p>\nAnd imagine the havoc if you could take the hibernated process\nand copy it to another machine, and then attempt to restore it there.\n<\/p>\n<p>\nIf you want some sort of &#8220;checkpoint \/ fast restore&#8221; functionality\nin your program, you&#8217;ll have to write it yourself.\nThen you will have to deal explicitly with issues like the above.\n(&#8220;I want to open this file, but somebody deleted it in the meantime.\nWhat should I do?&#8221;\nOr\n&#8220;Okay, I&#8217;m about to create a checkpoint, I&#8217;d better purge all my buffers\nand mark all my cached data as invalid because the thing I&#8217;m\ncaching might change while I&#8217;m in suspended animation.&#8221;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows lets you hibernate the entire machine, but why can&#8217;t it hibernate just one process? Record the state of the process and then resume it later. Because there is state in the system that is not part of the process. For example, suppose your program has taken a mutex, and then it gets process-hibernated. Oops, [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-39723","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>Windows lets you hibernate the entire machine, but why can&#8217;t it hibernate just one process? Record the state of the process and then resume it later. Because there is state in the system that is not part of the process. For example, suppose your program has taken a mutex, and then it gets process-hibernated. Oops, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/39723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=39723"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/39723\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=39723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=39723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=39723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}