{"id":1923,"date":"2014-01-30T07:00:00","date_gmt":"2014-01-30T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/01\/30\/can-process-ids-be-greater-than-64000-because-were-seeing-process-ids-greater-than-64000\/"},"modified":"2014-01-30T07:00:00","modified_gmt":"2014-01-30T07:00:00","slug":"can-process-ids-be-greater-than-64000-because-were-seeing-process-ids-greater-than-64000","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140130-00\/?p=1923","title":{"rendered":"Can process IDs be greater than 64000? Because we&#039;re seeing process IDs greater than 64000"},"content":{"rendered":"<p>\nA customer asked what to me was a very strange question.\n<\/p>\n<blockquote CLASS=\"q\"><p>\nCan process IDs be greater than 64000?\nBecause we&#8217;re seeing process IDs greater than 64000.\n<\/p><\/blockquote>\n<p>\nThis is a strange question because the answer is right there:\nYou&#8217;re seeing process IDs greater than 64000\nwith your very own eyes.\nDo you doubt the evidence right there in front of you?\n<\/p>\n<p>\nIt&#8217;s like asking,\n&#8220;Is it possible to have an orange with no seeds?\nBecause I have an orange with no seeds.&#8221;\n<\/p>\n<p>\nWe saw some time ago that\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/01\/06\/10112270.aspx\">\nprocess IDs can get very high indeed<\/a>,\nalthough the kernel tries to keep the numbers small purely\nfor cosmetic reasons.\n<\/p>\n<p>\nThe customer explained why they were asking this question.\n<\/p>\n<blockquote CLASS=\"q\">\n<p>\nOur application is crashing when the process ID gets too large.\nHere is the code:\n<\/p>\n<pre>\nint eventId = System.Diagnostics.Process.GetCurrentProcess().Id;\nEventLog.WriteEntry(\"Contoso\",\n                    message,\n                    EventLogEntryType.Information,\n                    eventId);\n<\/pre>\n<\/blockquote>\n<p>\nOkay, um, that code makes no sense.\n<\/p>\n<p>\nThe code uses the process ID as the event ID.\nBut event IDs are static;\nthey are\n<a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa363651(v=vs.85).aspx\">\nreferences to messages in your event source&#8217;s\nmessage table<\/a>.\nIt&#8217;s not like your message table contains 65535 entries like this:\n<\/p>\n<pre>\nMessageId=1\nSeverity=Informational\nSymbolicName=MSG_PROCESSID_1\nLanguage=English\nAn event occurred in Process ID 1: %1\n.\nMessageId=2\nSeverity=Informational\nSymbolicName=MSG_PROCESSID_2\nLanguage=English\nAn event occurred in Process ID 2: %1\n.\nMessageId=3\nSeverity=Informational\nSymbolicName=MSG_PROCESSID_3\nLanguage=English\nAn event occurred in process ID 3: %1\n.\n&hellip; and so on until &hellip;\nMessageId=3\nSeverity=Informational\nSymbolicName=MSG_PROCESSID_65535\nLanguage=English\nAn event occurred in process ID 65535: %1\n.\n<\/pre>\n<p>\nThe event ID describes what happened,\nand the process ID and other information goes into the\npayload.\n<\/p>\n<p>\nYou can see from the format of event IDs that the event number\ncan be at most 65535 because the upper bits of the event ID\nare used to encode other information.\n<\/p>\n<p>\nAnd the code crashes because the\n<code>Write&shy;Entry<\/code> method\nspecifically checks for absurd event IDs\nand rejects them with an\n<code>Argument&shy;Exception<\/code>.\n<\/p>\n<p>\nThe fix is therefore to put the process ID in the payload of your\nevent\nand let the event number describe what actually happened,\nlike\n&#8220;A multi-part print job was created.&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer asked what to me was a very strange question. Can process IDs be greater than 64000? Because we&#8217;re seeing process IDs greater than 64000. This is a strange question because the answer is right there: You&#8217;re seeing process IDs greater than 64000 with your very own eyes. Do you doubt the evidence right [&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-1923","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer asked what to me was a very strange question. Can process IDs be greater than 64000? Because we&#8217;re seeing process IDs greater than 64000. This is a strange question because the answer is right there: You&#8217;re seeing process IDs greater than 64000 with your very own eyes. Do you doubt the evidence right [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1923","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=1923"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1923\/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=1923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=1923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=1923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}