flybywire flybywire - 1 year ago 127
Linux Question

linux: kill background task

How do I kill the last spawned background task in linux?

Example:

doSomething
doAnotherThing
doB &
doC
doD
#kill doB
????

Answer Source

There's a special variable for this in bash:

kill $!

$! expands to the PID of the last process executed in the background.