如何使用“kill"结合“grep"杀死进程 [英] How to kill a process with 'kill' combined with 'grep'

查看:43
本文介绍了如何使用“kill"结合“grep"杀死进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个简单的命令杀死一个进程/脚本.目前我做以下事情

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

但是有没有办法将这 2 个命令组合在一起,这样我就不需要查看和手动编写 pid,就像这样 kill grep myscriptname?

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?

推荐答案

你想要pkill:

pkill myscriptname

在某些系统上有一个名为 killall 的类似工具,但要小心,因为在 Solaris 上它确实会杀死一切!

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

请注意,还有 pgrep 可用于替换 ps |grep 管道:

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

pgrep myscriptname

它会为您打印 PID,仅此而已.

It prints the PID for you, and nothing else.

这篇关于如何使用“kill"结合“grep"杀死进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆