Saturday, August 23, 2008

kill process or kill user in Linux

'kill'

"kill" is a very explicit word. It implies 'death'. In the last part of this lesson we talked about process IDs or "PIDs". Well, with the command 'kill' plus a PID, you can terminate a program. In other words, you kill the program. You will probably only use this with troublesome processes; programs that may not let you exit regularly. A good example of this is when you try a new program that hasn't got all the bugs worked out of it yet. If the 'exit' button doesn't work, you can 'kill' it.

To do this, first, you would type ps and you would get this output that we talked about before.

PID TTY STAT TIME COMMAND
293 2 S 0:00 -bash
422 2 S 0:00 sh /usr/X11R6/bin/startx
437 2 S 0:00 tee /home/bob/.X.err
438 2 S 0:00 xinit /home/bob/.xinitrc --
441 2 S 0:01 /usr/X11R6/bin/evilaliens

Let's say you're trying a new game that was just ported to Linux. The game is called "Evil and Nasty Alien Visitors". The name of the "binary" or program itself is called evilaliens. (the last one on my 'ps' example) It's a beta (i.e - check it out and tell the author what bugs are still in it) version and the game starts giving you problems. Now you can't exit the program either. The aliens just took over Oklahoma and you swore you got them all. You're playing in your x-windows enviroment and you have an x-terminal open (probably the one you typed 'ps' into). You would just type:

kill and the PID number, in my example, 441. That is: kill 441

and the program disappears, along with all those nasty aliens.

Here's a little trick. If you don't want to do two steps, 'ps' and 'kill' and you know the name of the "binary" or program itself, as I mentioned before, you can just type:

killall evilaliens

and that should also do the trick.

Using 'kill' as root

Remember that when you work as root, you are the all-powerful master of the universe. (or at least the computer). When you use 'kill' as root, you are the 007 on Her Majesty's Linux Service. You have license to 'kill' the process you desire. If you're working as 'root' and you need to use the 'kill' command, it's a good idea to run ps -au and look closely at your PIDs. You don't want to end up killing some process that you need.

Another way to kill a process.

Try typing this: find *. (Kind of an absurd thing to do, but good as an example) It will just start finding everything. If you have done something like this by mistake, you can use the keys CTR+ C to stop the 'find' process. In these cases, there's no need to use the 'kill' command.

0 comments:

Other Blog Posts by Maintainer

ICT News of Bangladesh

Linux Lews - Power by Google