linux shell:如何从文件中读取命令参数?

发布于 2024-08-10 06:35:31 字数 198 浏览 2 评论 0原文

我在文件“pid”中有进程 ID 我想杀了它。

就像:

kill -9 <read pid from file>

我尝试过:

kill -9 `more pid` 

但它不起作用。我也尝试过 xargs 但无法理解它。

I have process id in a file "pid"
I'd like to kill it.

Something like:

kill -9 <read pid from file>

I tried:

kill -9 `more pid` 

but it does not work. I also tried xargs but can't get my head around it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

方觉久 2024-08-17 06:35:31

吗?

kill -9 $(cat pid)

对你有用

Does

kill -9 $(cat pid)

work for you?

醉南桥 2024-08-17 06:35:31

让我总结一下所有答案

kill -9 $(cat pid)
kill -9 `cat pid`
cat pid | xargs kill -9

Let me summarize all answers

kill -9 $(cat pid)
kill -9 `cat pid`
cat pid | xargs kill -9
删除会话 2024-08-17 06:35:31

我的偏好是

kill -9 `cat pid`

这适用于反引号中的任何命令。

my preference is

kill -9 `cat pid`

that will work for any command in the backticks.

陌路终见情 2024-08-17 06:35:31

kill -9 $(cat pid)cat pid | xargs Kill -9 都可以工作

kill -9 $(cat pid) or cat pid | xargs kill -9 will both work

维持三分热 2024-08-17 06:35:31

你应该逐渐开始,然后转向繁重的东西来终止进程,如果它不想很好地运行的话。

无法捕获 SIGKILL (-9) 信号,这意味着进程持有的任何资源都不会被清除。

首先尝试使用kill SIGTERM (-15),然后仍然通过执行kill -0 $(cat pid) 检查进程是否存在。如果它仍然存在,那么无论如何用 -9 来破坏它。

SIGTERM 可以被进程捕获,任何正确编写的进程都应该有一个信号处理程序来捕获 SIGTERM,然后在退出之前清理其资源。

You should be starting off gradually and then move up to the heavy stuff to kill the process if it doesn't want to play nicely.

A SIGKILL (-9) signal can't be caught and that will mean that any resources being held by the process won't be cleaned up.

Try using a kill SIGTERM (-15) first and then check for the presence of the process still by doing a kill -0 $(cat pid). If it is still hanging around, then by all means clobber it with -9.

SIGTERM can be caught by a process and any process that has been properly written should have a signal handler to catch the SIGTERM and then clean up its resources before exiting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文