How to kill a process with 'kill' combined with 'grep'

15,464

Solution 1

You want pkill:

pkill myscriptname

On some systems there is a similar tool called killall, but be careful because on Solaris it really does kill everything!

Note that there is also pgrep which you can use to replace your ps | grep pipeline:

pgrep myscriptname

It prints the PID for you, and nothing else.

Solution 2

Another alternative is using the pidof command:

kill $(pidof processname)

Solution 3

you can try this simple trick pkill -f "my_sript_filename"

Share:
15,464
eduvv
Author by

eduvv

Updated on June 04, 2022

Comments

  • eduvv
    eduvv almost 2 years

    I'd like to kill a process/script with a simple command using. At the moment I do the following

    ps -ef | grep myscriptname
    kill 123456
    

    But is there a way to maybe combine the 2 command together so I don't need to look and manually write the pid, something like this kill grep myscriptname?