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?

6
  • Can you show us what you're running, i.e. show us how you connect and the for loop that is being executed. Commented May 25, 2017 at 12:34
  • 2
    There are many ways to do that. The simplest is probably to use tmux or screen. Commented May 25, 2017 at 12:39
  • 1
    take a look here Commented May 25, 2017 at 12:39
  • You can also use nohup to run the command.. Commented May 25, 2017 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 Commented May 25, 2017 at 13:14

2 Answers 2

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.

2
  • Thanks. Will try that. What about processor strain on local machine? Commented May 25, 2017 at 15:11
  • The strain will be as much as normally running the command over SSH. Commented May 25, 2017 at 15:14
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.