This question already has an answer here:

I am running a command on a server. It comes with this library http://www.graphicsmagick.org/.

Basically I have a for loop that does image procession on a lot of files.

Command runs for hours and will run for hours. I am wondering, can I exit ssh and still have those commands running on remote machine? Does exiting ssh sends some signal to end current command execution?

The other thing that I noticed..Although I am running command remotely, my laptop is overheating. Activity monitor shows bash is using 70% of cpu. I am on macbook pro

Now this is strange. How can remote command cause strain on local machine?

marked as duplicate by Gilles ssh May 25 '17 at 22:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Can you show us what you're running, i.e. show us how you connect and the for loop that is being executed. – EightBitTony May 25 '17 at 12:34
  • 2
    There are many ways to do that. The simplest is probably to use tmux or screen. – Satō Katsura May 25 '17 at 12:39
  • 1
    take a look here – Yaron May 25 '17 at 12:39
  • You can also use nohup to run the command.. – ryekayo May 25 '17 at 13:02
  • The command: for i in *.png; do for pos6 in *.png; do gm composite $i $pos6 overlays/${i/.png/}/${i/.png/}${pos6/.png/}.png ; done; done . I use ssh command to connect to server – sanjihan May 25 '17 at 13:14

When a session leader with associated controlling terminal (bash, in your case) exits, the operating system sends SIGHUP to all processes in the foreground process group (foreground job). Additionally, bash sends by default the SIGHUP to all its jobs, running or stopped (stopped jobs are also sent SIGCONT). Now the default action upon receiving SIGHUP is the process termination.

There are then several approaches to letting the process running after bash exits. First, you can make your process immune to SIGHUP; this is what the nohup command does. Second, you can background the corresponding process group and instruct bash not to send SIGHUP to it; this is what the disown shell builtin is used for (note also that there is a huponexit shell option, which causes SIGHUP to be sent to all jobs when an interactive login shell exits).

If you wish to reattach a terminal to the process group after you log in again, you may want to use a wrapper capable of this; terminal multiplexers such as screen have this functionality.


One solution is to prefix the command with nohup. This tells the computer to ignore 'hangup' signals (such as exiting an ssh session). This MAY NOT WORK with for loops.

Another good solution (and my personal favorite way to do this) is you install the 'screen' package. screen provides a virtual terminal that can be disconnected from, leaving processes running by pressing CTRL + A , D. The screen can then be reconnected to later with screen -r.

  • +1 for screen. So useful. – ivanivan May 25 '17 at 14:21
  • Thanks. Will try that. What about processor strain on local machine? – sanjihan May 25 '17 at 15:11
  • The strain will be as much as normally running the command over SSH. – Caleb Huggins May 25 '17 at 15:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.