Demystifying the svchost.exe process (and finding out what process is actually running under it)

I ran into this the other day at work and thought I would share.  Hopefully this will save you some time.  I had a service on a windows box that locked up during a standard service restart.  Seeing as most people don’t like having their server rebooted during the day I had to come up with a way to deal with this.  My usual fix for this was to determine what exe the service was running, hunt it down in task manager, manually kill it, and start the service again.  However, when I looked at the service I saw that the listed executable was ‘svchost.exe’.  Knowing that I would encounter more than one svchost.exe process when I opened task manager I decided to spend some time and figure out exactly what the exe was. 

What is svchost.exe?
As it turns out, not all applications and services in windows have the ‘exe’ file extension.  Some of them are actually DLLs (Dynamic-Link Library) files that need a means to run.  Windows (unlike other operating systems) doesn’t have a way to run a DLL directly as a service.  Svchost acts as a platform (a separate EXE) from which to launch these DLLs are services.  So when you see a ton of svchost.exe processes running under task manager, they aren’t actually the same program. 

So which one is which?
So lets walk through an example of how to determine which svchost process is linked to a particular program.  So lets say that the DHCP client service on my windows server locked up and during the service restart the service hung in the dreaded ‘Attempting to stop’ state (Yes, I realize its highly unlikely that your DHCP client service would be a critical service on a server with a static IP, just bear with me as the concept is the same for any service).  So I open up the services MMC and check the properties of the service to find out what EXE the service is running.  The properties screen looks like this…


As you can see, the service runs under the svchost.exe process.  A look at my task manager on the server gives me this…


Notice that I have not one, but fifteen svchost.exe processes running.  So which one do I kill?  After some googling I found the answer.  The key to making this determination is the PID (Process ID).  If you cant see the PID in your task manager go to View – Select Columns – And Select PID (For Server 08).   You should now see the PID listed next to each process.  Now go to the command prompt and enter in this magic command…

tasklist /svc

Or if you just want to see the svchost.exe processes…

tasklist /svc /fi "imagename eq svchost.exe"

The output from the second command looks like this…


A quick review of the output reveals that DHCP is running over svchost.exe at PID 956.  Taking a look back at the task manager I locate PID 956 and kill the process.  Pretty slick huh?

I view this way of starting and stopping windows services as a last resort.  Often times multiple services run under the same svchost which can cause issues if you start killing them.  Additionally, a lot of windows services that run as svchost.exe don’t like being killed.  For instance, the DHCP client I used in this example when killed just started right back up again.  If you can do a server reboot to clear the hung process that’s usually the best approach.  But if you can’t, and need a quick fix, use this with caution.

2 thoughts on “Demystifying the svchost.exe process (and finding out what process is actually running under it)

Leave a Reply

Your email address will not be published. Required fields are marked *