英文:
How to kill all processes from list in csv file
问题
我想编写一个Shell脚本,根据以下内容杀掉存储在txt文件中的所有PID:
83738 //分隔符为\n
394380
30984
...
基本上,我从Java启动这些进程,并将PID存储在该文件中,以防主线程出现问题。我希望避免逐个杀死它们(而不知道哪个Java进程是我的IDE)。
英文:
I would like to write a shell script that kills all the PID stored in a txt file as follows:
83738 //delimiter is \n
394380
30984
...
Basically, I start these from java and store the pid in this file in case something goes wrong on the main thread. I want to avoid killing them one by one (without knowing on which java is my IDE)
答案1
得分: 2
假设文件名为pids.txt,您可以使用:
xargs kill < pids.txt
xargs
是一个从标准输入读取文本,并将其作为命令行参数传递给另一个程序的程序。
英文:
Assuming the file is called pids.txt you can use:
xargs kill < pids.txt
xargs
is a program that reads text from standard input, and passes them as command line arguments to another program.
答案2
得分: 1
这可以轻松地这样完成:
while read -r pid; do
kill $pid;
done < pid.txt
英文:
This can easily be done like so:
while read -r pid; do
kill $pid;
done < pid.txt
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论