how to kill job in background?

9,248

Solution 1

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

Solution 2

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.

Share:
9,248

Related videos on Youtube

Phantom1421
Author by

Phantom1421

Updated on September 18, 2022

Comments

  • Phantom1421
    Phantom1421 almost 2 years

    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?"

  • Phantom1421
    Phantom1421 about 8 years
    so there is no such thing as killing a process in the background?
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 6 years
    That kills all processes called tail, not just background jobs of the current shell.