tags:

views:

88

answers:

2

I run the following code unsuccessfully

sudo killall %4

where %4 is my Vim session.

How can you terminate a job without foregrounding it?

+3  A: 

Try kill %4 instead. The unix shell uses %x as variables for currently running processes. To see the processes you can use with the %x syntax, use jobs. Killall is a wrapper around "kill" that is basically the equivalent of `ps -aux | grep | cut -f2 -d " " | xargs kill' or the like if you're a shell junky.

No, sorry, that shell command won't quite work, but it does illustrate how killall works =p. It simply kills every process it can that matches the string you provide.

Also, try `man kill' to learn more about kill. Particularly, kill -9 you may find useful. It's sorta the equivalent of 'force quit'.

easel
@Erik: Thank you for your explanation about how killall works. It seems that however: killall does NOT include kill mathematically: see Chris' code example.
Masi
+2  A: 

I believe you want "kill" instead of "killall". I tested under tcsh like this:

home% cat
^Z
Suspended
home% kill %1
home% 
[1]    Terminated                    cat

Furthermore, I doubt this would work with sudo because sudo would invoke a new shell, wouldn't it? And in that shell, %4 would not be defined.

home% cat
^Z
Suspended
home% sudo kill %1
Password:
kill: illegal process id: %1

If you really need to sudo, you can try this:

home% jobs -l
[1] + 26318 Suspended cat
home% sudo kill 26318
Chris Dolan
good point on the sudo. without using sudo -, you should still inherit some of the shell environment though... hmm...
easel
Thank you for your answer! I used initially kill, but it did not work for my Vim process. I therefore use killall with sudo in my code example to make my command my powerful. It is now obvious for me that sudo does not make the command more powerful, and that killall does not make the command kill more powerful, neither.
Masi
Hey - another Erik!
Erik Forbes