Saturday, November 20, 2010

Windows tools: handle and taskkill

It's been a while since I posted on system administration! Here are two findings - probably trivial, but new for me. 

Who's locking?

Say you can't open, move or delete a file on a Window system because it is locked by another process. How do you find out which process is responsible? To handle this question use Handle, a utility from Sysinternals suite. Basic usage:

handle <file name>

<process name> can be the full file name or any part of it. There are a few handy options, e.g. -c to close the handle in question. Handle is pretty much an equivalent of fuser(1) on Linux.

Killing hung service

It happens from time to time that a service gets stuck in "Stopping" or "Starting" state. How can you kill it without rebooting the entire machine? On Windows Server 2003 or 2008 the built-in taskkill command-line utility can help. Use the following syntax:

taskkill /fi "SERVICE eq <servicename>" /f

where <servicename> is the name of the service that has hung (you can see it under "Service name" in service's properties window in Services console). For example:

taskkill /fi "SERVICE eq TlntSvr" /f

kills Telnet service, if it happens to get stuck. Taskkill has many options, e.g. it can kill a process by PID with /pid switch. The /f switch forces termination of an unresponsive process.

 

 

 

No comments: