Kill question

Can a wildcard (*), be used with a kill statment?

for example, if you wanted to kill all process starting with 123, could you run kill 123*

or to kill all process, could you type

kill*
thanks
loserbrewerAsked:
Who is Participating?
 
TintinConnect With a Mentor Commented:
The * would be expanded (it's called shell globbing) to all the files/dirs in the directory you are running the command from.

For example, if your current directory has the following files

foo
bar

then kill * gets expanded to

kill foo bar
0
 
alienvoiceCommented:
From my experience you cannot do a straight 'kill -9 *'

You can issue a 'killall' command, but I'd becareful issuing it.

Do a 'man killall' for further information on this command.

0
 
omarfaridCommented:
if you wand to do similar thing, then you may filter the processes ids (e.g. using grep) then use kill to terminate processes:

for pid in `ps -ef | grep -v -i ppid | awk '{ print $2 }' | grep ^123`
do
   kill -9 $pid
done

or

kill -9  `ps -ef | grep -v -i ppid | awk '{ print $2 }' | grep ^123`



0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
TintinCommented:
What practical purpose do you have for needing this?

If your system has pkill, I'm sure you'd find that a lot more useful.
0
 
kishored2004Commented:
The kill command should be used with utmost caution unless you have the luxury of playing around..All said and done you should always try to kill the process gracefully first with the normal kill command before using the kill -9 which will do a forceful kill.

I also feel as said above...just grep on the process and use a normal kill. If that doesnt work do a forceful kill.
0
 
loserbrewerAuthor Commented:
This was more of a theoretical question. I am just learning UNIX and dont have a system I can work on.

So, does any one think a Kill command will work with a wildcard?
0
 
IncisiveOneCommented:
No.
0
 
TintinCommented:
Short answer no.  Longer answer, I can't think of any possible practical purpose for this, hence my question about what you wanted to use it for.

pkill is much more useful as it allows you to kill processes based on their name.
0
 
loserbrewerAuthor Commented:
Thank you for the responses. Anyone know what would happen if you ran kill*, would you get an error or would it look for a process called "*"
0
All Courses

From novice to tech pro — start learning today.