Is there a shell command that will kill all background tail processes
bash, kill, pid
Solution
You can refer to background jobs in your current shell with the `%1`, `%2`, ... idioms.
To my knowledge there's no such thing as a catch all; there's no `%*` or an equivalent.
But you could shortcut with
kill %1 %2 %3 %4 %5 %6 %7 %8
Which would kill the first eight background processes still running in your current shell. That may or may not be a `tail`.
Be careful whom you kill ;-)
If you have full control of the background processes this might be a safe bet for you. Since you mention that you want to do this from a shell script, and if the `tail`s are the only background processes, then this is straightforward. Just make sure your shell script starts a subshell, so that it never affects the background processes of an interactive shell. For instance you could start your script with
#!/usr/bin/bash
and set execute permission bits on the script and always call the script by name. In other words, you should not `source script_file` that script.
On the other hand, jim's answer to save the pids (process ids) of any process you are starting is a much more safe way of killing other processes.
Problem
If I run a script that starts several processes with the `&` like ``` tail -f log file1 & tail -f log file2 & ``` How can i shut them all down at once?