How to terminate a background process?
Clash Royale CLAN TAG#URR8PPP
I have started a wget on remote machine in background using &
. Suddenly it stops downloading. I want to terminate its process, then re-run the command. How can I terminate it?
I haven't closed its shell window. But as you know it doesn't stop using Ctrl+C and Ctrl+Z.
command-line process kill background-process jobs
add a comment |
I have started a wget on remote machine in background using &
. Suddenly it stops downloading. I want to terminate its process, then re-run the command. How can I terminate it?
I haven't closed its shell window. But as you know it doesn't stop using Ctrl+C and Ctrl+Z.
command-line process kill background-process jobs
add a comment |
I have started a wget on remote machine in background using &
. Suddenly it stops downloading. I want to terminate its process, then re-run the command. How can I terminate it?
I haven't closed its shell window. But as you know it doesn't stop using Ctrl+C and Ctrl+Z.
command-line process kill background-process jobs
I have started a wget on remote machine in background using &
. Suddenly it stops downloading. I want to terminate its process, then re-run the command. How can I terminate it?
I haven't closed its shell window. But as you know it doesn't stop using Ctrl+C and Ctrl+Z.
command-line process kill background-process jobs
command-line process kill background-process jobs
edited Jan 25 '17 at 16:36
Stéphane Chazelas
309k57582940
309k57582940
asked Dec 12 '13 at 7:11
Mohammad EtemaddarMohammad Etemaddar
6,70651730
6,70651730
add a comment |
add a comment |
8 Answers
8
active
oldest
votes
There are many ways to go about this.
Method #1 - ps
You can use the ps
command to find the process ID for this process and then use the PID to kill the process.
Example
$ ps -eaf | grep [w]get
saml 1713 1709 0 Dec10 pts/0 00:00:00 wget ...
$ kill 1713
Method #2 - pgrep
You can also find the process ID using pgrep
.
Example
$ pgrep wget
1234
$ kill 1234
Method #3 - pkill
If you're sure it's the only wget
you've run you can use the command pkill
to kill the job by name.
Example
$ pkill wget
Method #4 - jobs
If you're in the same shell from where you ran the job that's now backgrounded. You can check if it's running still using the jobs
command, and also kill it by its job number.
Example
My fake job, sleep
.
$ sleep 100 &
[1] 4542
Find it's job number. NOTE: the number 4542 is the process ID.
$ jobs
[1]+ Running sleep 100 &
$ kill %1
[1]+ Terminated sleep 100
Method #5 - fg
You can bring a backgrounded job back to the foreground using the fg
command.
Example
Fake job, sleep
.
$ sleep 100 &
[1] 4650
Get the job's number.
$ jobs
[1]+ Running sleep 100 &
Bring job #1 back to the foreground, and then use Ctrl+C.
$ fg 1
sleep 100
^C
$
Thejobs
has nooutput
andfg
sais:-bash: fg: 1: no such job
. But typingfg
works well and alsopkill wget
works well. butps -eaf|grep wget
and thenkill <process number>
dose not stop the job. ps: I use the third number as process number.
– Mohammad Etemaddar
Dec 12 '13 at 7:32
1
@MohammadEtemaddar - use the 2nd number from the output ofps
. The 3rd # is the parent's process id.
– slm♦
Dec 12 '13 at 7:34
1
@MohammadEtemaddar - ah, the ps is finding the grep. Do it like this:ps -eaef| grep [w]get
.
– slm♦
Dec 12 '13 at 7:54
1
@MohammadEtemaddar - you can also usepgrep
instead,pgrep wget
.
– slm♦
Dec 12 '13 at 7:56
2
@MohammadEtemaddar - sorry the extra e is a typo. Should readps -eaf | grep [w]get
. The options are are in theps
man page.man ps
.
– slm♦
Dec 12 '13 at 8:01
|
show 8 more comments
In bash you can use fg
to get the job to the foreground and then use Ctrl+C
Or list the process in the background with jobs
and then do
kill %1
(with 1 replaced by the number jobs
gave you)
add a comment |
You can equally use kill $!
to kill the most recently backgrounded job.
add a comment |
EDIT: Once in the foreground, you can Ctrl+C, or as @Zelda mentions, kill with the '%x' where 'x' is the job number will send the default signal (most likely SIGTERM in the case of Linux).
just type fg
to bring it to the foreground, if it was the last process you backgrounded (with '&').
If it was not the last one, type: jobs
and find the 'job number', represented in ''. Then just type:
fg 2
..where '2' is the job number, for example:
foo@bar:~/junk/books$ jobs
[1]+ Running okular how_to_cook_a_turkey.pdf &
foo@bar:~/junk/books$ fg 1
okular how_to_cook_a_turkey.pdf <- this is now in the foreground.
add a comment |
The correct way is to type jobs
then use the job number to kill it. In order to use the pid to kill it you need to bring it to the foreground as noted in the first answer.
Try this
~/Desktop$ sleep 1000 &
[1] 7056
~/Desktop$ jobs
[1]+ Running sleep 1000 &
/Desktop$ kill %1 #(%1 is the job number)
If you run jobs right after you kill it you should see this
Desktop$ jobs
[1]+ Terminated sleep 1000
add a comment |
One thing I don't see here, which I've found very useful especially when testing out commands, is pidof
. You can use pidof [command]
to find the process id of a process that is currently running. I like it because it allows me to quickly find the id of the command I want, which is usually something I just invoked.
Once you have the pid, you can simply kill the process. It allows for creating simple scripts for killing a process only if it's currently running.
1
Ah this helped me! kill %1 wasn't working for some reason, "kill: failed to parse argument: '%1'" and Ctrl+C wasn't working; couldn't find process in ps or anything because it was root (I forgot I used sudo with it)
– mjohnsonengr
Mar 23 '17 at 15:47
add a comment |
A common example is the stress
tool. Let say you ran the following:
$ stress -c 4 -m 4
and closed the terminal window. The process would continue eating your resources from the background.
Hers’s what I do:
$ x=`pgrep stress` ; sudo kill -9 $x
pgrep
lists the PIDs of the subjected process and stores it into variable x
which then used by kill -9
to terminate it.
add a comment |
in bash last stopped process (Ctrl-Z) you will kill by:
kill %%
kill -9 %%
or if want to choose, use:
jobs
then:
kill %N
like kill %2
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f104821%2fhow-to-terminate-a-background-process%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are many ways to go about this.
Method #1 - ps
You can use the ps
command to find the process ID for this process and then use the PID to kill the process.
Example
$ ps -eaf | grep [w]get
saml 1713 1709 0 Dec10 pts/0 00:00:00 wget ...
$ kill 1713
Method #2 - pgrep
You can also find the process ID using pgrep
.
Example
$ pgrep wget
1234
$ kill 1234
Method #3 - pkill
If you're sure it's the only wget
you've run you can use the command pkill
to kill the job by name.
Example
$ pkill wget
Method #4 - jobs
If you're in the same shell from where you ran the job that's now backgrounded. You can check if it's running still using the jobs
command, and also kill it by its job number.
Example
My fake job, sleep
.
$ sleep 100 &
[1] 4542
Find it's job number. NOTE: the number 4542 is the process ID.
$ jobs
[1]+ Running sleep 100 &
$ kill %1
[1]+ Terminated sleep 100
Method #5 - fg
You can bring a backgrounded job back to the foreground using the fg
command.
Example
Fake job, sleep
.
$ sleep 100 &
[1] 4650
Get the job's number.
$ jobs
[1]+ Running sleep 100 &
Bring job #1 back to the foreground, and then use Ctrl+C.
$ fg 1
sleep 100
^C
$
Thejobs
has nooutput
andfg
sais:-bash: fg: 1: no such job
. But typingfg
works well and alsopkill wget
works well. butps -eaf|grep wget
and thenkill <process number>
dose not stop the job. ps: I use the third number as process number.
– Mohammad Etemaddar
Dec 12 '13 at 7:32
1
@MohammadEtemaddar - use the 2nd number from the output ofps
. The 3rd # is the parent's process id.
– slm♦
Dec 12 '13 at 7:34
1
@MohammadEtemaddar - ah, the ps is finding the grep. Do it like this:ps -eaef| grep [w]get
.
– slm♦
Dec 12 '13 at 7:54
1
@MohammadEtemaddar - you can also usepgrep
instead,pgrep wget
.
– slm♦
Dec 12 '13 at 7:56
2
@MohammadEtemaddar - sorry the extra e is a typo. Should readps -eaf | grep [w]get
. The options are are in theps
man page.man ps
.
– slm♦
Dec 12 '13 at 8:01
|
show 8 more comments
There are many ways to go about this.
Method #1 - ps
You can use the ps
command to find the process ID for this process and then use the PID to kill the process.
Example
$ ps -eaf | grep [w]get
saml 1713 1709 0 Dec10 pts/0 00:00:00 wget ...
$ kill 1713
Method #2 - pgrep
You can also find the process ID using pgrep
.
Example
$ pgrep wget
1234
$ kill 1234
Method #3 - pkill
If you're sure it's the only wget
you've run you can use the command pkill
to kill the job by name.
Example
$ pkill wget
Method #4 - jobs
If you're in the same shell from where you ran the job that's now backgrounded. You can check if it's running still using the jobs
command, and also kill it by its job number.
Example
My fake job, sleep
.
$ sleep 100 &
[1] 4542
Find it's job number. NOTE: the number 4542 is the process ID.
$ jobs
[1]+ Running sleep 100 &
$ kill %1
[1]+ Terminated sleep 100
Method #5 - fg
You can bring a backgrounded job back to the foreground using the fg
command.
Example
Fake job, sleep
.
$ sleep 100 &
[1] 4650
Get the job's number.
$ jobs
[1]+ Running sleep 100 &
Bring job #1 back to the foreground, and then use Ctrl+C.
$ fg 1
sleep 100
^C
$
Thejobs
has nooutput
andfg
sais:-bash: fg: 1: no such job
. But typingfg
works well and alsopkill wget
works well. butps -eaf|grep wget
and thenkill <process number>
dose not stop the job. ps: I use the third number as process number.
– Mohammad Etemaddar
Dec 12 '13 at 7:32
1
@MohammadEtemaddar - use the 2nd number from the output ofps
. The 3rd # is the parent's process id.
– slm♦
Dec 12 '13 at 7:34
1
@MohammadEtemaddar - ah, the ps is finding the grep. Do it like this:ps -eaef| grep [w]get
.
– slm♦
Dec 12 '13 at 7:54
1
@MohammadEtemaddar - you can also usepgrep
instead,pgrep wget
.
– slm♦
Dec 12 '13 at 7:56
2
@MohammadEtemaddar - sorry the extra e is a typo. Should readps -eaf | grep [w]get
. The options are are in theps
man page.man ps
.
– slm♦
Dec 12 '13 at 8:01
|
show 8 more comments
There are many ways to go about this.
Method #1 - ps
You can use the ps
command to find the process ID for this process and then use the PID to kill the process.
Example
$ ps -eaf | grep [w]get
saml 1713 1709 0 Dec10 pts/0 00:00:00 wget ...
$ kill 1713
Method #2 - pgrep
You can also find the process ID using pgrep
.
Example
$ pgrep wget
1234
$ kill 1234
Method #3 - pkill
If you're sure it's the only wget
you've run you can use the command pkill
to kill the job by name.
Example
$ pkill wget
Method #4 - jobs
If you're in the same shell from where you ran the job that's now backgrounded. You can check if it's running still using the jobs
command, and also kill it by its job number.
Example
My fake job, sleep
.
$ sleep 100 &
[1] 4542
Find it's job number. NOTE: the number 4542 is the process ID.
$ jobs
[1]+ Running sleep 100 &
$ kill %1
[1]+ Terminated sleep 100
Method #5 - fg
You can bring a backgrounded job back to the foreground using the fg
command.
Example
Fake job, sleep
.
$ sleep 100 &
[1] 4650
Get the job's number.
$ jobs
[1]+ Running sleep 100 &
Bring job #1 back to the foreground, and then use Ctrl+C.
$ fg 1
sleep 100
^C
$
There are many ways to go about this.
Method #1 - ps
You can use the ps
command to find the process ID for this process and then use the PID to kill the process.
Example
$ ps -eaf | grep [w]get
saml 1713 1709 0 Dec10 pts/0 00:00:00 wget ...
$ kill 1713
Method #2 - pgrep
You can also find the process ID using pgrep
.
Example
$ pgrep wget
1234
$ kill 1234
Method #3 - pkill
If you're sure it's the only wget
you've run you can use the command pkill
to kill the job by name.
Example
$ pkill wget
Method #4 - jobs
If you're in the same shell from where you ran the job that's now backgrounded. You can check if it's running still using the jobs
command, and also kill it by its job number.
Example
My fake job, sleep
.
$ sleep 100 &
[1] 4542
Find it's job number. NOTE: the number 4542 is the process ID.
$ jobs
[1]+ Running sleep 100 &
$ kill %1
[1]+ Terminated sleep 100
Method #5 - fg
You can bring a backgrounded job back to the foreground using the fg
command.
Example
Fake job, sleep
.
$ sleep 100 &
[1] 4650
Get the job's number.
$ jobs
[1]+ Running sleep 100 &
Bring job #1 back to the foreground, and then use Ctrl+C.
$ fg 1
sleep 100
^C
$
edited Dec 12 '13 at 16:20
Ramchandra Apte
1054
1054
answered Dec 12 '13 at 7:21
slm♦slm
253k71535686
253k71535686
Thejobs
has nooutput
andfg
sais:-bash: fg: 1: no such job
. But typingfg
works well and alsopkill wget
works well. butps -eaf|grep wget
and thenkill <process number>
dose not stop the job. ps: I use the third number as process number.
– Mohammad Etemaddar
Dec 12 '13 at 7:32
1
@MohammadEtemaddar - use the 2nd number from the output ofps
. The 3rd # is the parent's process id.
– slm♦
Dec 12 '13 at 7:34
1
@MohammadEtemaddar - ah, the ps is finding the grep. Do it like this:ps -eaef| grep [w]get
.
– slm♦
Dec 12 '13 at 7:54
1
@MohammadEtemaddar - you can also usepgrep
instead,pgrep wget
.
– slm♦
Dec 12 '13 at 7:56
2
@MohammadEtemaddar - sorry the extra e is a typo. Should readps -eaf | grep [w]get
. The options are are in theps
man page.man ps
.
– slm♦
Dec 12 '13 at 8:01
|
show 8 more comments
Thejobs
has nooutput
andfg
sais:-bash: fg: 1: no such job
. But typingfg
works well and alsopkill wget
works well. butps -eaf|grep wget
and thenkill <process number>
dose not stop the job. ps: I use the third number as process number.
– Mohammad Etemaddar
Dec 12 '13 at 7:32
1
@MohammadEtemaddar - use the 2nd number from the output ofps
. The 3rd # is the parent's process id.
– slm♦
Dec 12 '13 at 7:34
1
@MohammadEtemaddar - ah, the ps is finding the grep. Do it like this:ps -eaef| grep [w]get
.
– slm♦
Dec 12 '13 at 7:54
1
@MohammadEtemaddar - you can also usepgrep
instead,pgrep wget
.
– slm♦
Dec 12 '13 at 7:56
2
@MohammadEtemaddar - sorry the extra e is a typo. Should readps -eaf | grep [w]get
. The options are are in theps
man page.man ps
.
– slm♦
Dec 12 '13 at 8:01
The
jobs
has no output
and fg
sais: -bash: fg: 1: no such job
. But typing fg
works well and also pkill wget
works well. but ps -eaf|grep wget
and then kill <process number>
dose not stop the job. ps: I use the third number as process number.– Mohammad Etemaddar
Dec 12 '13 at 7:32
The
jobs
has no output
and fg
sais: -bash: fg: 1: no such job
. But typing fg
works well and also pkill wget
works well. but ps -eaf|grep wget
and then kill <process number>
dose not stop the job. ps: I use the third number as process number.– Mohammad Etemaddar
Dec 12 '13 at 7:32
1
1
@MohammadEtemaddar - use the 2nd number from the output of
ps
. The 3rd # is the parent's process id.– slm♦
Dec 12 '13 at 7:34
@MohammadEtemaddar - use the 2nd number from the output of
ps
. The 3rd # is the parent's process id.– slm♦
Dec 12 '13 at 7:34
1
1
@MohammadEtemaddar - ah, the ps is finding the grep. Do it like this:
ps -eaef| grep [w]get
.– slm♦
Dec 12 '13 at 7:54
@MohammadEtemaddar - ah, the ps is finding the grep. Do it like this:
ps -eaef| grep [w]get
.– slm♦
Dec 12 '13 at 7:54
1
1
@MohammadEtemaddar - you can also use
pgrep
instead, pgrep wget
.– slm♦
Dec 12 '13 at 7:56
@MohammadEtemaddar - you can also use
pgrep
instead, pgrep wget
.– slm♦
Dec 12 '13 at 7:56
2
2
@MohammadEtemaddar - sorry the extra e is a typo. Should read
ps -eaf | grep [w]get
. The options are are in the ps
man page. man ps
.– slm♦
Dec 12 '13 at 8:01
@MohammadEtemaddar - sorry the extra e is a typo. Should read
ps -eaf | grep [w]get
. The options are are in the ps
man page. man ps
.– slm♦
Dec 12 '13 at 8:01
|
show 8 more comments
In bash you can use fg
to get the job to the foreground and then use Ctrl+C
Or list the process in the background with jobs
and then do
kill %1
(with 1 replaced by the number jobs
gave you)
add a comment |
In bash you can use fg
to get the job to the foreground and then use Ctrl+C
Or list the process in the background with jobs
and then do
kill %1
(with 1 replaced by the number jobs
gave you)
add a comment |
In bash you can use fg
to get the job to the foreground and then use Ctrl+C
Or list the process in the background with jobs
and then do
kill %1
(with 1 replaced by the number jobs
gave you)
In bash you can use fg
to get the job to the foreground and then use Ctrl+C
Or list the process in the background with jobs
and then do
kill %1
(with 1 replaced by the number jobs
gave you)
answered Dec 12 '13 at 7:17
ZeldaZelda
4,8321526
4,8321526
add a comment |
add a comment |
You can equally use kill $!
to kill the most recently backgrounded job.
add a comment |
You can equally use kill $!
to kill the most recently backgrounded job.
add a comment |
You can equally use kill $!
to kill the most recently backgrounded job.
You can equally use kill $!
to kill the most recently backgrounded job.
edited Jan 25 '17 at 16:37
Anthony Geoghegan
7,83153954
7,83153954
answered Jan 25 '17 at 15:39
tek0078tek0078
8316
8316
add a comment |
add a comment |
EDIT: Once in the foreground, you can Ctrl+C, or as @Zelda mentions, kill with the '%x' where 'x' is the job number will send the default signal (most likely SIGTERM in the case of Linux).
just type fg
to bring it to the foreground, if it was the last process you backgrounded (with '&').
If it was not the last one, type: jobs
and find the 'job number', represented in ''. Then just type:
fg 2
..where '2' is the job number, for example:
foo@bar:~/junk/books$ jobs
[1]+ Running okular how_to_cook_a_turkey.pdf &
foo@bar:~/junk/books$ fg 1
okular how_to_cook_a_turkey.pdf <- this is now in the foreground.
add a comment |
EDIT: Once in the foreground, you can Ctrl+C, or as @Zelda mentions, kill with the '%x' where 'x' is the job number will send the default signal (most likely SIGTERM in the case of Linux).
just type fg
to bring it to the foreground, if it was the last process you backgrounded (with '&').
If it was not the last one, type: jobs
and find the 'job number', represented in ''. Then just type:
fg 2
..where '2' is the job number, for example:
foo@bar:~/junk/books$ jobs
[1]+ Running okular how_to_cook_a_turkey.pdf &
foo@bar:~/junk/books$ fg 1
okular how_to_cook_a_turkey.pdf <- this is now in the foreground.
add a comment |
EDIT: Once in the foreground, you can Ctrl+C, or as @Zelda mentions, kill with the '%x' where 'x' is the job number will send the default signal (most likely SIGTERM in the case of Linux).
just type fg
to bring it to the foreground, if it was the last process you backgrounded (with '&').
If it was not the last one, type: jobs
and find the 'job number', represented in ''. Then just type:
fg 2
..where '2' is the job number, for example:
foo@bar:~/junk/books$ jobs
[1]+ Running okular how_to_cook_a_turkey.pdf &
foo@bar:~/junk/books$ fg 1
okular how_to_cook_a_turkey.pdf <- this is now in the foreground.
EDIT: Once in the foreground, you can Ctrl+C, or as @Zelda mentions, kill with the '%x' where 'x' is the job number will send the default signal (most likely SIGTERM in the case of Linux).
just type fg
to bring it to the foreground, if it was the last process you backgrounded (with '&').
If it was not the last one, type: jobs
and find the 'job number', represented in ''. Then just type:
fg 2
..where '2' is the job number, for example:
foo@bar:~/junk/books$ jobs
[1]+ Running okular how_to_cook_a_turkey.pdf &
foo@bar:~/junk/books$ fg 1
okular how_to_cook_a_turkey.pdf <- this is now in the foreground.
edited Dec 12 '13 at 7:39
Anthon
61k17104166
61k17104166
answered Dec 12 '13 at 7:20
swisscheeseswisscheese
28128
28128
add a comment |
add a comment |
The correct way is to type jobs
then use the job number to kill it. In order to use the pid to kill it you need to bring it to the foreground as noted in the first answer.
Try this
~/Desktop$ sleep 1000 &
[1] 7056
~/Desktop$ jobs
[1]+ Running sleep 1000 &
/Desktop$ kill %1 #(%1 is the job number)
If you run jobs right after you kill it you should see this
Desktop$ jobs
[1]+ Terminated sleep 1000
add a comment |
The correct way is to type jobs
then use the job number to kill it. In order to use the pid to kill it you need to bring it to the foreground as noted in the first answer.
Try this
~/Desktop$ sleep 1000 &
[1] 7056
~/Desktop$ jobs
[1]+ Running sleep 1000 &
/Desktop$ kill %1 #(%1 is the job number)
If you run jobs right after you kill it you should see this
Desktop$ jobs
[1]+ Terminated sleep 1000
add a comment |
The correct way is to type jobs
then use the job number to kill it. In order to use the pid to kill it you need to bring it to the foreground as noted in the first answer.
Try this
~/Desktop$ sleep 1000 &
[1] 7056
~/Desktop$ jobs
[1]+ Running sleep 1000 &
/Desktop$ kill %1 #(%1 is the job number)
If you run jobs right after you kill it you should see this
Desktop$ jobs
[1]+ Terminated sleep 1000
The correct way is to type jobs
then use the job number to kill it. In order to use the pid to kill it you need to bring it to the foreground as noted in the first answer.
Try this
~/Desktop$ sleep 1000 &
[1] 7056
~/Desktop$ jobs
[1]+ Running sleep 1000 &
/Desktop$ kill %1 #(%1 is the job number)
If you run jobs right after you kill it you should see this
Desktop$ jobs
[1]+ Terminated sleep 1000
edited Sep 2 '14 at 18:28
drs
3,32362861
3,32362861
answered Sep 2 '14 at 18:06
tmactmac
411
411
add a comment |
add a comment |
One thing I don't see here, which I've found very useful especially when testing out commands, is pidof
. You can use pidof [command]
to find the process id of a process that is currently running. I like it because it allows me to quickly find the id of the command I want, which is usually something I just invoked.
Once you have the pid, you can simply kill the process. It allows for creating simple scripts for killing a process only if it's currently running.
1
Ah this helped me! kill %1 wasn't working for some reason, "kill: failed to parse argument: '%1'" and Ctrl+C wasn't working; couldn't find process in ps or anything because it was root (I forgot I used sudo with it)
– mjohnsonengr
Mar 23 '17 at 15:47
add a comment |
One thing I don't see here, which I've found very useful especially when testing out commands, is pidof
. You can use pidof [command]
to find the process id of a process that is currently running. I like it because it allows me to quickly find the id of the command I want, which is usually something I just invoked.
Once you have the pid, you can simply kill the process. It allows for creating simple scripts for killing a process only if it's currently running.
1
Ah this helped me! kill %1 wasn't working for some reason, "kill: failed to parse argument: '%1'" and Ctrl+C wasn't working; couldn't find process in ps or anything because it was root (I forgot I used sudo with it)
– mjohnsonengr
Mar 23 '17 at 15:47
add a comment |
One thing I don't see here, which I've found very useful especially when testing out commands, is pidof
. You can use pidof [command]
to find the process id of a process that is currently running. I like it because it allows me to quickly find the id of the command I want, which is usually something I just invoked.
Once you have the pid, you can simply kill the process. It allows for creating simple scripts for killing a process only if it's currently running.
One thing I don't see here, which I've found very useful especially when testing out commands, is pidof
. You can use pidof [command]
to find the process id of a process that is currently running. I like it because it allows me to quickly find the id of the command I want, which is usually something I just invoked.
Once you have the pid, you can simply kill the process. It allows for creating simple scripts for killing a process only if it's currently running.
answered Jun 23 '16 at 4:08
garzaigarzai
14612
14612
1
Ah this helped me! kill %1 wasn't working for some reason, "kill: failed to parse argument: '%1'" and Ctrl+C wasn't working; couldn't find process in ps or anything because it was root (I forgot I used sudo with it)
– mjohnsonengr
Mar 23 '17 at 15:47
add a comment |
1
Ah this helped me! kill %1 wasn't working for some reason, "kill: failed to parse argument: '%1'" and Ctrl+C wasn't working; couldn't find process in ps or anything because it was root (I forgot I used sudo with it)
– mjohnsonengr
Mar 23 '17 at 15:47
1
1
Ah this helped me! kill %1 wasn't working for some reason, "kill: failed to parse argument: '%1'" and Ctrl+C wasn't working; couldn't find process in ps or anything because it was root (I forgot I used sudo with it)
– mjohnsonengr
Mar 23 '17 at 15:47
Ah this helped me! kill %1 wasn't working for some reason, "kill: failed to parse argument: '%1'" and Ctrl+C wasn't working; couldn't find process in ps or anything because it was root (I forgot I used sudo with it)
– mjohnsonengr
Mar 23 '17 at 15:47
add a comment |
A common example is the stress
tool. Let say you ran the following:
$ stress -c 4 -m 4
and closed the terminal window. The process would continue eating your resources from the background.
Hers’s what I do:
$ x=`pgrep stress` ; sudo kill -9 $x
pgrep
lists the PIDs of the subjected process and stores it into variable x
which then used by kill -9
to terminate it.
add a comment |
A common example is the stress
tool. Let say you ran the following:
$ stress -c 4 -m 4
and closed the terminal window. The process would continue eating your resources from the background.
Hers’s what I do:
$ x=`pgrep stress` ; sudo kill -9 $x
pgrep
lists the PIDs of the subjected process and stores it into variable x
which then used by kill -9
to terminate it.
add a comment |
A common example is the stress
tool. Let say you ran the following:
$ stress -c 4 -m 4
and closed the terminal window. The process would continue eating your resources from the background.
Hers’s what I do:
$ x=`pgrep stress` ; sudo kill -9 $x
pgrep
lists the PIDs of the subjected process and stores it into variable x
which then used by kill -9
to terminate it.
A common example is the stress
tool. Let say you ran the following:
$ stress -c 4 -m 4
and closed the terminal window. The process would continue eating your resources from the background.
Hers’s what I do:
$ x=`pgrep stress` ; sudo kill -9 $x
pgrep
lists the PIDs of the subjected process and stores it into variable x
which then used by kill -9
to terminate it.
edited Jul 16 '18 at 11:10
slm♦
253k71535686
253k71535686
answered Jun 11 '18 at 2:18
Saptarshi GhoshSaptarshi Ghosh
111
111
add a comment |
add a comment |
in bash last stopped process (Ctrl-Z) you will kill by:
kill %%
kill -9 %%
or if want to choose, use:
jobs
then:
kill %N
like kill %2
add a comment |
in bash last stopped process (Ctrl-Z) you will kill by:
kill %%
kill -9 %%
or if want to choose, use:
jobs
then:
kill %N
like kill %2
add a comment |
in bash last stopped process (Ctrl-Z) you will kill by:
kill %%
kill -9 %%
or if want to choose, use:
jobs
then:
kill %N
like kill %2
in bash last stopped process (Ctrl-Z) you will kill by:
kill %%
kill -9 %%
or if want to choose, use:
jobs
then:
kill %N
like kill %2
edited Feb 12 at 16:32
answered Feb 12 at 16:26
Sławomir LenartSławomir Lenart
1011
1011
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f104821%2fhow-to-terminate-a-background-process%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown