Linux run progress in background & screen usage

  1. Run in background
  2. Run in background with Screen

Run in background

# run in background
{command to run} &

# run in background and write stdout and stderr to 'output.log' file

# 2 refers to the second file descriptor of the process, i.e. stderr.
# > means redirection.
# &1 means the target of the redirection should be the same location as the first file descriptor, i.e. stdout.
{command to run} 2>&1 > output.log &

# https://www.brianstorti.com/understanding-shell-script-idiom-redirect/

Run in background with Screen

# create screen name terraria
# ctrl+a+d to return to orgin terminal
# still running after ssh connect stopped
screen -S terraria

# ls all screen
screen -ls

# back to screen name terraria
screen -r terraria

# kill screen session by name
# screen -X -S [session # you want to kill] quit
screen -X -S terraria quit

./tModLoaderServer -config serverconfig.txt
# ./tModLoaderServer -config serverconfig.txt 2>&1 > output.log &

# ctrl+a+d to return to orgin terminal

# kill all detached session
screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill

# kill all dead(unreachable) session
screen -wipe