I started a program in the background on a remote machine through ssh using nohup ./program &
I want to kill/stop this program on remote machine as it seems like an infinite loop.
How can I do that?
Please help
1 Answer
The brute solution [If you are not logged in after running the command ]:
ssh to that machine and then find the process id (pid) of the process that you want to kill by running the ps ax | grep <any regex part of the command that you ran> [e.g. ps ax | grep java]. After that a simple kill <pid> should do the trick.
The easier solution [If you are still in the console of that machine after running the command]: do a simple fg, that'd bring the process to the foreground and later you can do a ctrl + c. Or you can follow the similar process of finding the pid and killing the same.
Reply in case you need more assistance.
-
Thanks. I ran
ps ax | grep progand it gave me:40697 pts/0 S+ 0:00 grep --color=auto progAnd when I typeps ax | grep progrit gives me:40699 pts/0 S+ 0:00 grep --color=auto progrWhat is the proces sif? 40697 or 40699?user140704– user1407042015-10-29 05:32:17 +00:00Commented Oct 29, 2015 at 5:32 -
@user140704: buddy neither of this will help you. Can you tell the command which you ran, the one you want to kill now? I need the full the command please.Tanny– Tanny2015-10-29 06:41:58 +00:00Commented Oct 29, 2015 at 6:41
-
In
ps ax (or l,-f,etc) |grep xyzthepslist includes thepsandgrepprocesses themselves and thegrepmatches and shows itself, in addition to the desired process(es). If looking for program name only not commandline argument(s), usingpsdefault format (noxetc) avoids this. Otherwise, common workarounds are|grep program |grep -v grepor|awk '/program/&&!/awk/'or a pattern tweak like|grep '[p]rogram'. Or better just usepgrep(with-lif you want to manually verify) which excludes itself, plus defaults to all processes.dave_thompson_085– dave_thompson_0852015-10-29 10:31:34 +00:00Commented Oct 29, 2015 at 10:31 -
thanks for your help. Actually the process was killed due to memory error. Thats why not showing up.user140704– user1407042015-10-29 12:46:36 +00:00Commented Oct 29, 2015 at 12:46
-