Search code examples
javalinuxshellpid

How to kill all processes from list in csv file


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)


Solution

  • 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.