I use the command pkill
for this:
NAME
pgrep, pkill - look up or signal processes based on name and
other attributes
SYNOPSIS
pgrep [options] pattern
pkill [options] pattern
DESCRIPTION
pgrep looks through the currently running processes and lists
the process IDs which match the selection criteria to stdout.
All the criteria have to match. For example,
$ pgrep -u root sshd
will only list the processes called sshd AND owned by root.
On the other hand,
$ pgrep -u root,daemon
will list the processes owned by root OR daemon.
pkill will send the specified signal (by default SIGTERM)
to each process instead of listing them on stdout.
If your code runs via interpreter (java, python, ...) then the name of the process is the name of the interpreter. You need to user the argument --full. This matches against the command name and the arguments.