如何终止CSV文件中列表中的所有进程。

huangapple go评论86阅读模式
英文:

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 &lt; 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 &lt; pid.txt

huangapple
  • 本文由 发表于 2020年8月19日 22:46:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63489567.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定