{"id":34553,"date":"2005-08-17T10:00:10","date_gmt":"2005-08-17T10:00:10","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/08\/17\/why-is-processor-affinity-inherited-by-child-processes\/"},"modified":"2005-08-17T10:00:10","modified_gmt":"2005-08-17T10:00:10","slug":"why-is-processor-affinity-inherited-by-child-processes","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050817-10\/?p=34553","title":{"rendered":"Why is processor affinity inherited by child processes?"},"content":{"rendered":"<p>Consider why a typical program launches child processes. (Shell programs like Explorer aren&#8217;t typical.) It&#8217;s because the task at hand is being broken down into sub-tasks which for whatever reason  has been placed into a child process. An Example of this would be, say, a multi-pass compiler\/linker, where each pass is implemented as a separate process in a pipeline.<\/p>\n<p> Now consider why you might want to set a process&#8217;s affinity mask to restrict it to a single processor. One reason is that the program may have bugs that cause it to crash or behave erratically on multi-processor machines. This was common for older programs that were written for uni-processor versions of Windows or when multi-processor machines were still prohibitively expensive. In this case, you would launch the program in a suspended state, by passing <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/dllproc\/base\/process_creation_flags.asp\"> the <code>CREATE_SUSPENDED<\/code> flag<\/a> to <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/dllproc\/base\/createprocess.asp\"> the <code>CreateProcess<\/code> function<\/a>, then set the processor affinity mask for that process to a single processor, then resume the process&#8217;s main thread. <\/p>\n<p> But what if the problem was in a child process of the process you&#8217;re launching? Since you don&#8217;t have control over how the process launches its child, you have no way to sneak in and set the child process&#8217;s processor affinity mask. That&#8217;s why the processor affinity mask is inherited: If you set it on the parent process, this covers all the child helper processes that process may launch as part of its execution. <\/p>\n<p> Another reason why you might want to set a process&#8217;s affinity mask is to restrict its CPU usage. (For example, you might restrict a CPU-intensive application to a single processor of your dual-processor machine.) And again, if the process launches child processes, you want those child processes to be subject to the same restriction as their parent so that the task as a whole remains restricted to a single processor. <\/p>\n<p> That&#8217;s why processor affinity is inherited by child processes. Because it&#8217;s nearly always what you want. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Consider why a typical program launches child processes. (Shell programs like Explorer aren&#8217;t typical.) It&#8217;s because the task at hand is being broken down into sub-tasks which for whatever reason has been placed into a child process. An Example of this would be, say, a multi-pass compiler\/linker, where each pass is implemented as a separate [&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":[25],"class_list":["post-34553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Consider why a typical program launches child processes. (Shell programs like Explorer aren&#8217;t typical.) It&#8217;s because the task at hand is being broken down into sub-tasks which for whatever reason has been placed into a child process. An Example of this would be, say, a multi-pass compiler\/linker, where each pass is implemented as a separate [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/34553","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=34553"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/34553\/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=34553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=34553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=34553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}