This question does not appear to be about a specific programming problem, a software algorithm, or software too开发者_如何学Cls primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this questionserver01:/# 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
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
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
kill -9 can be used as a last resort to ensure the process dies.....
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>
.
kill -9 $(pgrep -f keyword)
.
Kill pid(s) searched by 'KEYWORD';
kill $(pgrep [search pattern])
See if that works better. You have to be either root or the process owner to kill a process.
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.
精彩评论