Incoming from windows - easy taskkill

Write tutorials and howtos in here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

Incoming from windows - easy taskkill

Postby shingetsu on Mon Jul 02, 2012 3:23 am

Ok, now this is for all you people coming in from windows (it can be useful to veterans too, though as a light utility, nothing more).
You probably remember this:
Code: Select all
taskkill /IM something.exe

Now when you tried doing, say, this:
Code: Select all
kill brasero

it asked you for a pid. After googling you did this:
Code: Select all
pidof brasero

and had to write it manually.
Well these days are over! There's actually a pretty simple way to get this working. I wrote a small (technically under 1kb) script that does it for you. The basic script is as follows:
Code: Select all
#!/bin/bash
#nkill by Shingetsu (http://forums.linuxmint.com/memberlist.php?mode=viewprofile&u=89380)
PROCS="$@"
for p in $PROCS
do
kill `pidof $p`
done

What this does: it accepts something like
Code: Select all
nkill brasero gedit firefox

(I call it nkill (n for Name)).
Basically the name of every process you send as an argument is checked, then killed. This sends the SIGTERM command. SIGTERM won't ALWAYS work, however It is safer though. For a more "effective script, consider this:
Code: Select all
#!/bin/bash
#fnkill by Shingetsu (http://forums.linuxmint.com/memberlist.php?mode=viewprofile&u=89380)
PROCS="$@"
for p in $PROCS
do
kill -9 `pidof $p`
done

The -9 here sends the SIGKILL signal. While always effective, and can result an consequences in certain cases.
I was going to make a last version of the script... one where 1st parameter decides whether to use -9 or not, but got lasy and just made the -9 version fnkill.

Anyway, put this script into /usr/bin under the name nkill and/or fnkill and you can go around using it (should work in alt+f2 also).

Use this with great responsibility. Thank you all :P.

P.S.* Yes this is selfish propaganda. Yes this is still useful. The real reason I posted is in the case I kill my comp so I can get the script back.

P.S.S. * This should be compatible with sudo -> with it, the program would be run as root and as such all commands in it would have the "sudo su" effect. So that will work too.
User avatar
shingetsu
Level 1
Level 1
 
Posts: 28
Joined: Mon Jun 25, 2012 11:58 pm
Location: Montral, Canada

Linux Mint is funded by ads and donations.
 

Re: Incoming from windows - easy taskkill

Postby veggen on Mon Jul 02, 2012 6:06 am

What's wrong with killall? It kills by name and is already in your system.
User avatar
veggen
Level 4
Level 4
 
Posts: 401
Joined: Mon May 09, 2011 4:54 am

Re: Incoming from windows - easy taskkill

Postby eanfrid on Mon Jul 02, 2012 6:13 am

We even have xkill to kill an open window with a single mouse click :)
No, Linux is not a Windows clone for free - Before asking any question here...
"Never attribute to malice that which is adequately explained by stupidity." (Hanlon's razor)

Debian GNU/Linux Wheezy 64bit - MATE 1.8
User avatar
eanfrid
Level 6
Level 6
 
Posts: 1190
Joined: Mon Apr 30, 2012 2:49 am
Location: France

Re: Incoming from windows - easy taskkill

Postby shingetsu on Mon Jul 02, 2012 6:42 am

veggen wrote:What's wrong with killall? It kills by name and is already in your system.

killall is an excellent tool, but what I disliked of it was that:
1. It's not safe outside of linux (while this script can be used on unix safely)
2. killall doesn't kill impure executable, kill does. This is why this script uses kill, actually.
3. killall isn't often mentioned on searches. Whereas if a user types in "kill process linux" or "taskkill in linux" or similar, this is sure to pop up.
Thank you however, for mentioning it, now people that read it will also be aware of the alternative.

eanfrid wrote:We even have xkill to kill an open window with a single mouse click :)

Since when is xkill capable of killing all instances of multiple running executable? One of my main points was that one avoids typing multiple commands and just runs one single command (runnable from alt+f2).

After running a few benchmarks I noticed that nkill performs SLIGHTLY slower than killall -e, but about the same speed as killall (in some cases slightly faster, mainly in cases of multiple instances of multiple programs running).

If I made any outstanding mistake in my 3 clauses, please correct me. I got this idea around 3 am (and finished it around 3:15, if we include the research for better alternatives) so it's quite possible I did, in fact, make a mistake.
User avatar
shingetsu
Level 1
Level 1
 
Posts: 28
Joined: Mon Jun 25, 2012 11:58 pm
Location: Montral, Canada

Re: Incoming from windows - easy taskkill

Postby altair4 on Mon Jul 02, 2012 7:01 am

I'm confused by the premise.

Most windows users have never heard of taskkill. Most Windows users don't even know they have a terminal emulator and if they do they think they are running DOS. Most Windows users kill processes using Task Manager. The Linux ( Gnome ) equivalent is System Monitor: gnome-system-monitor.

Then it becomes System Monitor > Right click brasero > Kill Process
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
altair4
Level 15
Level 15
 
Posts: 5507
Joined: Tue Feb 03, 2009 10:27 am

Re: Incoming from windows - easy taskkill

Postby shingetsu on Mon Jul 02, 2012 8:27 am

altair4 wrote:I'm confused by the premise.

Most windows users have never heard of taskkill. Most Windows users don't even know they have a terminal emulator and if they do they think they are running DOS. Most Windows users kill processes using Task Manager. The Linux ( Gnome ) equivalent is System Monitor: gnome-system-monitor.

Then it becomes System Monitor > Right click brasero > Kill Process


Weird, I always used the cmd (when I was forced to use a windows install) and most windows users I know prefer a fast cmd command or a batch script rather than using the task manager. It's possible that my limited experience in the area lead to a false assumption based on an overly limited selection, however I believed the chance of that to be quite low.
User avatar
shingetsu
Level 1
Level 1
 
Posts: 28
Joined: Mon Jun 25, 2012 11:58 pm
Location: Montral, Canada

Re: Incoming from windows - easy taskkill

Postby fraze on Mon Jul 02, 2012 6:13 pm

This is definitely useful. Having left Win* some time ago, still the old habits creep up and I find myself using the odd backslash or Win* cmd. Filed this away just in case.

Thanks shingetsu.
fraze
Level 1
Level 1
 
Posts: 18
Joined: Sat Jun 30, 2012 7:16 pm

Linux Mint is funded by ads and donations.
 

Return to Tutorials / Howtos

Who is online

Users browsing this forum: No registered users and 14 guests