29

How to kill a running python in shell script when we know the python file name xxx.py? (it is executed by cmd python xxx.py)

I can use ps aux | grep python to get the pid of it. and then kill pid to terminate it.

but every time, I have to execute two cmd. Is there a good way to do it?

HenrySnoopy
  • 327
  • 1
  • 3
  • 8

1 Answers1

63

The pkill utility can look at command lines when sending signals:

pkill -f xxx.py
AKX
  • 152,115
  • 15
  • 115
  • 172