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

后端 未结 5 1479
-上瘾入骨i
-上瘾入骨i 2021-01-19 01:51

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

相关标签:
5条回答
  • 2021-01-19 02:03

    An alternative is piping to the xargs command:

    ps -ef | grep myscriptname | xargs kill

    http://man7.org/linux/man-pages/man1/xargs.1.html

    0 讨论(0)
  • 2021-01-19 02:13

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

    0 讨论(0)
  • 2021-01-19 02:19

    Another alternative, pgrep with xargs

    ps aux | pgrep gitlab | xargs kill

    0 讨论(0)
  • 2021-01-19 02:28

    Another alternative is using the pidof command:

    kill $(pidof processname)
    
    0 讨论(0)
  • 2021-01-19 02:29

    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.

    0 讨论(0)
提交回复
热议问题