0

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 1

0

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.

5
  • Thanks. I ran ps ax | grep prog and it gave me: 40697 pts/0 S+ 0:00 grep --color=auto prog And when I type ps ax | grep progr it gives me: 40699 pts/0 S+ 0:00 grep --color=auto progr What is the proces sif? 40697 or 40699? Commented 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. Commented Oct 29, 2015 at 6:41
  • In ps ax (or l,-f,etc) |grep xyz the ps list includes the ps and grep processes themselves and the grep matches and shows itself, in addition to the desired process(es). If looking for program name only not commandline argument(s), using ps default format (no x etc) avoids this. Otherwise, common workarounds are |grep program |grep -v grep or |awk '/program/&&!/awk/' or a pattern tweak like |grep '[p]rogram'. Or better just use pgrep (with -l if you want to manually verify) which excludes itself, plus defaults to all processes. Commented Oct 29, 2015 at 10:31
  • thanks for your help. Actually the process was killed due to memory error. Thats why not showing up. Commented Oct 29, 2015 at 12:46
  • Cool in that case!! Commented Nov 2, 2015 at 4:25

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.