3

I know how to kill a job with kill %(number) but is it possible to kill a job as background job, the question is "kill tail as a background job?"

2

There are several ways to specify jobs, including %foo to designate the job whose command starts with foo and %?foo to designate the job whose command contains the substring foo. You need to specify an unambiguous prefix or substring: if more than one string matches, the shell reports an error. This is a POSIX feature.

kill %tail

(Note that this is specifically to kill a background job of the current shell. If you want to kill all tail processes running as your user regardless of whether they're a job of the current shell, you can use pkill. Obviously, with a common utility such as tail, this could cause collateral damage; run the pgrep command with the same arguments first to see what would be killed.)

1

Killing it like any other process should work:

pkill tail

Though if you want to be careful with that, you can check the PID with top, htop, or ps ahead of time.

  • so there is no such thing as killing a process in the background? – Phantom1421 Mar 29 '16 at 19:04
  • That kills all processes called tail, not just background jobs of the current shell. – Gilles May 13 '18 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.