Search code examples
linuxprocesssignalskillpid

Killing processes with a single command?


When I run the command

ps -l -a

I get the list of all the processes currently running on the terminal. enter image description here

I know I can kill these processes by repeatedly invoking the command "kill" like this

kill -9 10400
kill -9 10401
kill -9 10418

but is there a way to kill them all with a single command and/or without specifying pids/names?


Solution

  • If you run these processes from a bash script and capture their pids by adding & pid=$! after the command, you can kill them one by one with their captured pids.

    If you need them killed a certain time, you can setup an 'at job' or a 'cron job' and pass the pids through the environment or a file. You can also save the pids somewhere for later use with a kill script.