linux shell:如何从文件中读取命令参数?
我在文件“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
吗?
对你有用
Does
work for you?
让我总结一下所有答案
Let me summarize all answers
我的偏好是
这适用于反引号中的任何命令。
my preference is
that will work for any command in the backticks.
kill -9 $(cat pid)
或cat pid | xargs Kill -9 都可以工作
kill -9 $(cat pid)
orcat pid | xargs kill -9
will both work你应该逐渐开始,然后转向繁重的东西来终止进程,如果它不想很好地运行的话。
无法捕获 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.