Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Advance apologies for what is probably a simple question. I have some basic questions about using ssh to run programs that I can't resolve via Google. I'm using Unix (via the program "Terminal" on Mac OS 10.6.7).

I am accessing a different machine using ssh. Once there, I'm running some code. This results in output files in a directory on that machine. I terminate a run by doing "control C." I get rid of the output files by doing:

find . -type f -name "*.vtk" -exec rm -f {} \;

The problem is that:

  1. The person whose machine it is tells me there are multiple versions of my code running. I don't understand how I'm not stopping these by doing "control C." Can anyone explain?

  2. Also (this might be related to the first problem), when I run the "find" command above to get rid of the output files, if I wait a few seconds/minutes, some output files have appeared again! Could this be related to the "ghost" versions of the code running, that I can't terminate?

If anyone could tell me how to make sure I have terminated ALL runs and how to get rid of ALL vtk (or other suffix) output files from a directory, I would really appreciate it. Also, any suggestions regarding online resources about all this ssh stuff would be very welcome. Thanks a lot.

share|improve this question

migrated from Apr 30 '11 at 13:20

This question came from our site for professional and enthusiast programmers.

SSH just allows you access to another machine's terminal, it has no special process management, this is all linux and could be emulated on a local machine. – rudi_visser Apr 30 '11 at 11:16
Ctrl+C normally terminates the program running in the terminal, but programs are allowed to catch the signal. Also, if the program is composed of several processes, it's possible that not all processes would be killed. Did you write that program, or are you just a user of it? What is that program? What variant of unix is running on the remote machine? Exactly what ssh command do you use to run the program? – Gilles Apr 30 '11 at 11:18
Thanks for your response, Gilles. I wrote the program. It's in C++. I compile it using "make" and then I run it using "./programName" What do you mean by "several processes?" Unfortunately, I don't know which version of unix is running on the remote machine. The ssh command I use to access the other machine is: ssh -X myUserName@ipAddressOfTheMachine. – Ant Apr 30 '11 at 11:24
@Ant: Run uname -sr on the remote machine to see what unix variant it's running. Do you use fork or signal handlers in your program, or a library that might use them under the hood? – Gilles Apr 30 '11 at 11:30
Thanks again Gilles... I get Linux as the output from uname -sr on the other machine. I don't know what fork or signal handlers are! Sorry for my ignorance. I do use "-X" when accessing the other machine, and that allows me to use an editor in my X11 (Mac) program. – Ant Apr 30 '11 at 11:35
up vote 1 down vote accepted

If you do not use tools like screen all your running programs will terminate once you logout from your ssh session. Also Ctrl + C will terminate the currently running foreground process. In case you started some background processes (either with & at the end of your command or Ctrl + z, bg you can make them become foreground processes by typing fg.

The program ps allows you to see currently running programs. There you should see any 'still running instances'. You can terminate them using kill -9 <PID> or killall -9 <prog-name>.

share|improve this answer
Thanks dcn. I have actually tried using killall. I do: ps -A | grep programName and then killall -9 programName. But I get a message saying that there are no executables running! – Ant Apr 30 '11 at 11:26
P.S. To logout from an ssh session, is it sufficient to simply close the window? – Ant Apr 30 '11 at 11:28
Also useful is running kill -1 as user (never root) which kills all process owned by that user. – Benjamin Bannier Apr 30 '11 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .