0

I have a machine that is running CentOs 7.7. I'm trying to access the terminal remotely, and execute a script. Right now I use putty to connect to server via SSH, and type ./run_server.sh to execute my script. The content of the run_server.sh file is as follows (extremely simplified):

#!/bin/bash
run_script=(./my_calculator_server)
"${run_script[@]}"

It then starts to execute my calculator server, which can accept two numbers and output their sum (again simplified). The problem is, if I close the Putty program, the script is terminated, so is the session. Even if the script is not terminated, I won't be able to go back to it since running Putty again will open a fresh terminal window. I want to be able to remotely access that session, interact with it and go back to it anytime I want. Is it possible? If so, what are my options?

I'm not asking for step-by-step instructions, only looking to find the ways to do this.

PS: VNC is not an option.

Johansson
  • 103

1 Answers1

1

Problem is that the process is a child process of your current shell session. When your shell closes, all child processes get terminated. You need to disown the process from the current shell:

I know of these three options:


disown:

Run your command, then press CTRL+Z to suspend the current process, run bg to let it continue in background and then run disown.


Use nohup if you need an easy way to get the output logged:

nohup your_command &

Find the output of your command in a file named nohoup.out by default.


Use a screen or tmux session if you need to reattach to your process.


Similar questions:

pLumo
  • 22,565
  • Thanks for the answer! Although I've already tried the first two. I wasn't able to go back to that session. I'm reading about tmux right now, if it supports resuming the session, it's just what I needed. – Johansson Mar 25 '20 at 10:24
  • I use screen for that. Never used tmux ;-) – pLumo Mar 25 '20 at 10:26