1

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?

sanjihan
  • 405
  • 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
  • Please ask one question at a time. I have closed your question as a duplicate for the first question in your post, which is what the answers here were about. The second question, “How can remote command cause strain on local machine?”, cannot be answered, it needs more information from you. Copy-paste the commands you run, and look at the output of top or htop to see what is using CPU time. Ask a new question about this, with the information that we requested. – Gilles 'SO- stop being evil' May 25 '17 at 22:45

2 Answers2

3

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.

3

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.

trosos
  • 339