Killing a process in linux

518 views Asked by At

I am trying to kill a process in linux

ps -aux
root     14074  0.0  0.4 6586120 67452 pts/0   Sl   22:45   0:01 java -cp target/cronscheduler-1.0-SNAPSHOT.jar com.cronscheduler.QuartzMain

Kill the process in the stop script using the below command

ps aux | grep "java -cp target/cronscheduler-1.0-SNAPSHOT.jar com.cronscheduler.QuartzMain" | \
grep -v grep | awk '{print $2}' | xargs kill -9

Issue is this command works fine when cronscheduler.QuartzMain is running. But when this process is already killed then the above command throws error

Usage:
 kill [options] <pid|name> [...]

Your inputs on removing the errors are appreciated

4

There are 4 answers

0
Sagar Parmar On
ps aux | grep httpd

httpd  3486  0.0  0.1   4248  1432 ?        S    Jul31   0:00 /usr/sbin/httpd -f /etc/httpd/httpd.conf

# kill 3486

OR

$ sudo kill 3486
2
clemens On

pkill can search through the complete command line. Try

pkill -9 -f 'java -cp target/cronscheduler-1.0-SNAPSHOT.jar com.cronscheduler.QuartzMain'

Your command may create errors, because it sends more than the pid (the complete line from ps) to kill.

0
P RAJESH On

Please try below this will help in clearing the child process id's as well.

for i in `ps -ef| grep "java -cp target/cronscheduler-1.0-SNAPSHOT.jar com.cronscheduler.QuartzMain" | grep -v grep | awk '{print $2}'`        
do
     ptree $i|awk '{print $1}' >>pids.txt
done
for i in $(cat pids.txt)
do
     kill -9 $i
done
0
Zaks On

One of the solution I found was to redirect the error message : cat /etc/*.conf 2> /dev/null