1

I've hacked together a solution that allows me to commit changes to my Go language application to Azure Websites, compile into a Go binary, and then update the Web.Config to have the httpPlatformHandler use the newly created binary. This allows me to easily deploy changes to my Go app and have them (almost) instantly available on my Azure website. It's a neat prototype, and you can check it out here: https://github.com/wadewegner/azure-website-go-builder/

If you look at the last line of the deploy.cmd you'll see that I use Powershell to kill a w3wp.exe process. This forces it to restart and use the updated Web.Config.

powershell "stop-process (Get-Process w3wp | Sort-Object ws | Select -first 1).Id"

This is a hack and not ideal. In a default scenario there are two w3wp.exe processes running - one for our website and one for the SCM website (which is a management website). It will not work if we have more than one instance of our Azure website running. It also assumes that the right process to kill is the one with the smaller memory footprint - this is a bad assumption to make.

In Azure Websites we don't have a lot of facilities at our disposal for finding and killing processes.

When I run Get-Process w3wp ... I get this kind of output today:

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName          
-------  ------    -----      ----- -----   ------     -- -----------          
    364      40     7196      16032    85     0.55   5516 w3wp                 
    667      77    61972      77372   350     5.72   3448 w3wp    

However, with two instances of my website, it could be:

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName          
-------  ------    -----      ----- -----   ------     -- -----------          
    364      40     7196      16032    85     0.55   5516 w3wp                 
    364      40     7196      16032    85     0.55   5517 w3wp    
    667      77    61972      77372   350     5.72   3448 w3wp    

(Manually updated to make my point.)

So, the question is, what's the right way to choose the two processes I want to kill? I don't want to kill 3448.

Additionally, how do I find a better heuristic to choose the right processes?

I uploaded tlist.exe to run tlist -t and get this output:

D:\home\site\wwwroot>tlist -t
AdjustTokenPrivileges failed with 1300
w3wp.exe (5516)
  20150107_070323.exe (4936)
w3wp.exe (3448)
  cmd.exe (1976)
    tlist.exe (5868)

This makes it clear that 5516 is the PID I want to kill.

Is there a way in Powershell to run Get-Process but if it somehow inspect child processes and filter out the w3wp.exe PID with the cmd.exe process?

Thank you!

Wade
  • 741
  • 1
  • 5
  • 18
  • [This](http://stackoverflow.com/questions/2855978/which-w3wp-exe-process-belongs-to-which-app-pool-in-iis6-with-powershell) or [this](http://odetocode.com/blogs/scott/archive/2006/07/18/powershell-and-apppool-names.aspx) might be at your disposal. If you want to interact with the apppool name. Assuming you know what it is. – Matt Jan 07 '15 at 18:17
  • [WMI](https://social.technet.microsoft.com/Forums/windowsserver/en-US/b761fc16-4d41-45a8-a925-2c5ebef33112/how-to-get-parent-process-id?forum=winserverpowershell) can also do this if that is an option which can return the parent process of an exe – Matt Jan 07 '15 at 18:18
  • WMI isn't available (public cloud). Nor is taskkill. iisapp.vbs doesn't appear to be on the box. – Wade Jan 07 '15 at 18:38
  • Tlist isn't available on my Windows 8.1 system. Where's that coming from? –  Jan 07 '15 at 19:04
  • As mentioned, I uploaded it to the instance simply to get another perspective. – Wade Jan 07 '15 at 19:06
  • What specifically are you looking at from the tlist output to ensure that it's the correct process to kill? Are you looking at the `cmd.exe` in the process chain? –  Jan 07 '15 at 19:08
  • tlist.exe is not the solution I'm looking for - it's not available by default on the box; it was only a temporary way to get more info. Ideally I want to use PowerShell. But yes, `cmd.exe` in the process chain is the ticket I think. How do I find this in PowerShell? – Wade Jan 07 '15 at 19:29
  • How about working backwards with the exe to find the parent w3wp.exe? http://poshcode.org/4548 – Matt Jan 07 '15 at 20:05
  • You could probably use WMI to identify the w3wp process based on its command line rather than looking at the chain of parent/child processes. Something like `gwmi Win32_Process -Filter "Name='w3wp.exe'" | fl Name, ProcessId, CommandLine`. – Mike Zboray Jan 07 '15 at 20:08
  • Great idea, but as mentioned, WMI is restricted in Azure Websites and unavailable. – Wade Jan 07 '15 at 20:16
  • @Wade interesting. I find it odd that you can upload and run an arbitrary tool (tlist) but you can't access WMI. So the native Win32 apis are available? The .NET `Process` class does not contain the required information to determine parent/child processes. – Mike Zboray Jan 07 '15 at 20:23
  • Do you have access to performance counters? You could work [this answer](http://stackoverflow.com/a/2336322/517852) into a solution using `Add-Type` to dynamically compile the C# code. – Mike Zboray Jan 07 '15 at 20:27
  • A good idea, @mikez, but sadly doesn't work. I wrote the following C# app which fails with message `System.UnauthorizedAccessException: Access to the registry key 'Global' is denied.` https://gist.github.com/wadewegner/193b74a0facbaeefe59d – Wade Jan 07 '15 at 21:26
  • I just learned from David Ebbo that, even if we were to find a way to use PowerShell to get the parent PID it turns out not all the website instances are available via Kudu. So, still hope to figure out how to do this in PowerShell, but ultimately it's a dead end. Thanks for all your help! – Wade Jan 07 '15 at 21:32
  • @Matt Just saw your code. That looks interesting and will try! – Wade Jan 07 '15 at 21:32

0 Answers0