Monday, March 5, 2007

Killing jobs and making penguins

This weeks Windows tip is a really long one, so you can skip straight to the examples if you are impatient.

Did you ever want to use a command line or batch file to kill a particular task? It can be done with a whole lot of options with 2 different command line tools.

tskill

It is used as follows:

tskill processed
or
tskill processname

For example:

tskill calc” will kill all instances of calc.exe, or “tskill winword” will kill all instances of Microsoft Word. (add /a at the end of the command and it will kill them for all users on that machine – only if you have administrative privileges)

You could use:
tskill processid

Use “Task Manager” or “tasklist” to find processid.
To find all options, - tskill /?

tskill is a nice tool but it is limited so you may prefer to use –

taskkill.
The syntax is: “taskkill /im imagename” where imagename is the full name of the program you want to kill (like calc.exe) or “taskkill /pid processed” . You can kill a number of processes in one line: taskkill /im calc.exe /im winword.exe /pid 27501 will kill all instances of calc.exe, winword.exe and process number 27501.
The processes can also be filtered out using the /fi parameter. Here you can use various functions such as eq (equals), ne (Not equal to), gt (greater than), lt (less than), ge (greater than or equal to) and le (less than or equal to).
You can now use those parameters against a number of different options: imagename (the name of the program), pid (process id), memusage (amount of memory being used by process), cputime (percentage of cpu being used by process) and more. (type tasskill /?)
By the way, adding the /f parameter will forcefully kill the process.
So, you may ask, “what is all this good for?”. Below are a number of examples and I am sure you can think of more.

Let’s say you want to kill all non-responding processes:
taskkill /f /fi "status eq not responding" (Note: you must include the quotation marks).

or
If you are running low in memory and want to close all processes using more than 35 Megabytes:
taskkill /f /fi "memusage gt 35000" (Again, you must include the quotation marks.)

"But that shut an important program down!!!!! Now I lost my PowerPoint presentation which I was working on for hours!!!!!!"

Well, you should have filtered it out:
taskkill /f /fi "imagename ne powerpnt.exe" /fi "memusage gt 35000"
will close all processes using more than 35 Megabytes except if the name is powerpnt.exe.

Pretty cool, no?

Linux:

How to make a paper penguin. (Thanks to http://linuxreviews.org )
Download the following .pdf file, print the first page and follow the instructions on the second page.
http://linuxreviews.org/howtos/penguin/penguin.pdf
(If you are asking what this has to do with Linux, then maybe this blog is not for you )

Don't hesitate to leave a comment. (And click the google ads if they look interesting)