Technology Tales

Adventures & experiences in contemporary technology

Killing Windows processes from the command line

26th September 2015

During my days at work, I often hear about the need to restart a server because something has gone awry with it. This makes me wonder if you can kill processes from the command line like you do in Linux and UNIX. A recent need to reset Windows Update on a Windows 10 machine gave me enough reason to answer the question.

Because I already knew the names of the services, I had no need to look at the Services tab in the Task Manager like you otherwise would. Then, it was a matter of opening up a command line session with Administrator privileges and issuing a command like the following (replacing [service name] with the name of the service):

sc queryex [service name]

From the output of the above command, you can find the process identifier, or PID. With that information, you can execute a command like the following in the same command line session (replacing [PID] with the actual numeric value of the PID):

taskkill /f /pid [PID]

After the above, the process no longer exists and the service can be restarted. With any system, you need to find the service that is stuck in order to kill it but that would be the subject of another posting. What I have not got to testing is whether these work in PowerShell since I used them with the legacy command line instead. Along with processes belonging to software applications (think Word, Excel, Firefox, etc.), that may be something else to try should the occasion arise.

Killing those runaway processes that refuse to die

5th July 2008

I must admit that there have been times when I logged off from my main Ubuntu box at home to dispatch a runaway process that I couldn’t kill and then log back in again. The standard signal being sent to the process by the very useful kill command just wasn’t sending the nefarious CPU-eating nuisance the right kind of signal. Thankfully, there is a way to control the signal being sent and there is one that does what’s needed:

kill -9 [ID of nuisance process]

For Linux users, there seems to be another option for terminating process that doesn’t need the ps and grep command combination: it’s killall. Generally, killall terminates all processes and its own has no immunity to its quest. Hence, it’s an administrator only tool with a very definite and perhaps rarely required use. The Linux variant is more useful because it also will terminate all instances of a named process at a stroke and has the same signal control as the kill command. It is used as follows:

killall -9 nuisanceprocess

I’ll certainly be continuing to use both of the above; it seems that Wine needs termination like this at times and VMware Workstation lapsed into the same sort of antisocial behaviour while running a VM running a development version of Ubuntu’s Intrepid Ibex (or 8.10, if you prefer). Anything that keeps you from constantly needing to restart Linux sessions on your PC has to be good.

UNIX Process Management

1st June 2007

Here are a few UNIX commands that I have recently encountered that help with process management and are particularly useful when jobs are running in the background. Here they are:

nohup

It’s short for no hang up and stops termination of a job when a user logs off. Another result is that all console messages being directed to a file called nohup.out in the directory current to the job being run, or in the user’s home directory where write access to the current working directory is unavailable.

ps

This returns a list of processes, their ID’s and their statuses. By default, this is for your own processes but you can look beyond this with the myriad of options that can be passed. For instance, the -U switch allows you to look at a job for other users while the -f one shows more information than the standard call and this even includes the commands submitted to start the ongoing processes.

kill

The name says it all and it’s far quicker than the rigmarole that you have to endure with the Windows task manager; I wonder if there is a command line approach to process termination on Windows.

  • All the views that you find expressed on here in postings and articles are mine alone and not those of any organisation with which I have any association, through work or otherwise. As regards editorial policy, whatever appears here is entirely of my own choice and not that of any other person or organisation.

  • Please note that everything you find here is copyrighted material. The content may be available to read without charge and without advertising but it is not to be reproduced without attribution. As it happens, a number of the images are sourced from stock libraries like iStockPhoto so they certainly are not for abstraction.

  • With regards to any comments left on the site, I expect them to be civil in tone of voice and reserve the right to reject any that are either inappropriate or irrelevant. Comment review is subject to automated processing as well as manual inspection but whatever is said is the sole responsibility of the individual contributor.