{"id":111427,"date":"2025-08-01T07:00:00","date_gmt":"2025-08-01T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111427"},"modified":"2025-08-01T09:58:31","modified_gmt":"2025-08-01T16:58:31","slug":"20250801-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20250801-00\/?p=111427","title":{"rendered":"Two related questions about keeping track of PIDs of IPC clients"},"content":{"rendered":"<p>A customer was writing a program that was intended to run in the background and was looking for recommendations on how to store its PID so that other programs can find it and start communicating with the background process.<\/p>\n<p>Another customer was writing a provider program that will have multiple clients connect to it. They want the program to know when all of its clients have exited, so that the provider program can exit, too. They were thinking of polling the list of running processes to see if any with names matching those of its clients is running. Is there a better way? Can they get the PIDs of the clients so they can wait for them?<\/p>\n<p>In both cases, the customer is working too hard.<\/p>\n<p>Since they already have an IPC mechanism for the clients to talk to the providers, they can just have the client pass its own PID to the provider as part of the initial connection. Now the provider has the PIDs and can convert them (via <code>OpenProcess<\/code>) into process handles and wait on the handles.<\/p>\n<p>The customers didn&#8217;t say what IPC mechanism they were using, but there may be features already built into the IPC mechanism they are using that provide the client PID,\u00b9 or even better, that let them know when the client has disconnected, since disconnection can happen even if the client process hasn&#8217;t yet exited. For example, if they are using a COM server, they can use the final <code>Release()<\/code> from the client to signal that the client has disconnected. If they are using an RPC server, they can use context rundown to detect that the client has disconnected.<\/p>\n<p>My point is that since you are already using IPC, you can use that IPC channel to pass the information you need.<\/p>\n<p>\u00b9 For example, you may be able to use the <code>Rpc\u00adServer\u00adInq\u00adCall\u00adAttributes<\/code> function to obtain the PID of an RPC client.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since you&#8217;re doing IPC, you may as well let IPC do the work for you.<\/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-111427","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Since you&#8217;re doing IPC, you may as well let IPC do the work for you.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111427","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=111427"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111427\/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=111427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}