Home:ALL Converter>Linux: kill background task

Linux: kill background task

Ask Time:2009-10-26T21:10:45         Author:flybywire

Json Formatter

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


doB &
#kill doB

Author:flybywire,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/1624691/linux-kill-background-task
John Kugelman :

You can kill by job number. When you put a task in the background you'll see something like:\n\n$ ./script &\n[1] 35341\n\n\nThat [1] is the job number and can be referenced like:\n\n$ kill %1\n$ kill %% # Most recent background job\n\n\nTo see a list of job numbers use the jobs command. More from man bash:\n\n\n There are a number of ways to refer to a job in the shell. The character % introduces a job name. Job number n may be\n referred to as %n. A job may also be referred to using a prefix of the name used to start it, or using a substring that\n appears in its command line. For example, %ce refers to a stopped ce job. If a prefix matches more than one job, bash\n reports an error. Using %?ce, on the other hand, refers to any job containing the string ce in its command line. If the\n substring matches more than one job, bash reports an error. The symbols %% and %+ refer to the shell's notion of the current job, which is the last job stopped while it was in the foreground or started in the background. The previous job may\n be referenced using %-. In output pertaining to jobs (e.g., the output of the jobs command), the current job is always\n flagged with a +, and the previous job with a -. A single % (with no accompanying job specification) also refers to the\n current job.\n",