tags:

views:

100

answers:

6
server01:/# ps -ax | grep java

Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html

 7342 pts/3    Z      0:00 [java] <defunct>

 7404 pts/3    S+     0:00 grep java


server01:/# kill 7342

server01:/# ps -ax | grep java

Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html

 7342 pts/3    Z      0:00 [java] <defunct>

 7406 pts/3    S+     0:00 grep java


server01:/# 

In the above I am using ps command to know the pid of the java process which is 7342 in the above case.

Then I killed that process using kill command. But that is not killed because again ps command shows java process with pid 7342.

Should I use some else command to kill the process and Why kill is not able to kill the process

Thanx

A: 
kill $(pgrep [search pattern])

See if that works better. You have to be either root or the process owner to kill a process.

jim mcnamara
A: 

try

ps aux

then

kill -1 PID_NUMBER

to ask program to close itself, if it dosn´t answer you can force it to close

kill -9 PID_NUMBER

remember that using -9 to force program will finalize without asking and not saving anything check: man kill for more details

fredcrs
keep in mind that kill -9 should be your last resort as it doesn't let child processes of the process you are killing die. so they become zombie processes.
kgb
A: 

kill -9 can be used as a last resort to ensure the process dies.....

ennuikiller
+5  A: 

Linux supports the BSD style switches to the ps command (without the leading - ... dash/hyphen). If one supplies the hypen then the GNU coreutils version of ps (the one which is standard on mainstream Linux distributions) will attempt to interpret the switches as SysV compatible. This is the source of your error.

I'd recommend using the BSD form of the switches and look up the -o option to specify an output format consisting ONLY of the PID of the matching processes.

Also you're attempting to kill a zombie. As you've discovered that's a futile effort. A zombie is a placeholder in the process able for a process which is already dead. It remains in the process table until its parent process "reaps" its exit code. If the parent never does a wait() system call then the entry will stay there until after the parent is killed, at which point the zombie (and any other orphaned processes) will be inherited by the init process. The normal init under Linux (or any other form of UNIX) periodically reaps all dead processes (zombies).

Conceptually every process that exits on a UNIX/Linux system spends a small amount of time as a "zombie" ... that is there should always be a period of time between the process' termination and the time when some other process reads its exit value (even if only to discard it, as init does).

This question really should go on ServerFault

Jim Dennis
Addition: by running `ps auxf` you'll see what the parent process is. It's either blocked too, or not paying attention to it's children.
vdboor
A: 

The process is listed as defunct. It's job is done and it's kept around because the parent process is still there. However, if the parent crashed or was killed by kill -9, there is no parent process, so the defunct process will kept around until reboot. Defunct (or zombie) processes use only minimal resources, so you can keep them.

Solution: Either kill the parent or use kill -9 <pid>.

Martin
Or, if you are getting frustrated, `kill -KILL <pid>`
James
Thanx for the knoledge.kill -9 <pid> is not working.can u tell command to find parent process.
sjain
A: 

The java process has become a zombie process. You should try sending the SIGCHLD signal to the parent process via kill to tell the parent process to reap the zombie child process. Failing that, as mentioned by @Martin, you could kill the parent or kill -9 the zombie process.

TheJuice