-1

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

jww
  • 97,681
  • 90
  • 411
  • 885
Zaks
  • 668
  • 1
  • 8
  • 30

4 Answers4

1

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.

clemens
  • 16,716
  • 11
  • 50
  • 65
0

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

Zaks
  • 668
  • 1
  • 8
  • 30
0
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
jww
  • 97,681
  • 90
  • 411
  • 885
0

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
jww
  • 97,681
  • 90
  • 411
  • 885
P RAJESH
  • 23
  • 3