Jeff Pang Jeff Pang - 9 months ago 58
Linux Question

How to kill python script with bash script

I run a bash script with which start a python script to run in background


python &

So how i can i kill the script with bash script also?

I used the following command to kill but output
no process found

killall $(ps aux | grep | grep -v grep | awk '{ print $1 }')

I try to check the running processes by
ps aux | less
and found that the running script having command of

Please assist, thank you!

Answer Source

Use pkill command as

pkill -f

(or) a more fool-proof way using pgrep to search for the actual process-id

kill $(pgrep -f 'python')