SURF Research Boot Camp 2018-04-10
Detach from work

HvA logo

UvA logo

SURF logo

This is an exercise from the Extras part of the Tutorial SURF Research Boot Camp 2018-04-10.

This exercise lets you experience the difference between local and remote computation: you can organize your work so that it continues after you close your laptop.

You will run a simple program that outputs a line each few seconds and experience what happens when you detach from the program in various ways.

Set-up

cd
nano example.sh
#!/bin/bash
while sleep 2
do
  date
done
chmod u+x example.sh
./example.sh

First detach

./example.sh
pstree
# look for a line like this:
#  ... -example.sh---sleep

Food for brain:

Is pstree command installed? If not, are you able to figure out how to install it? After all, you are the sysadmin!

Suggestion just in case:

Using nohup

nohup ./example.sh &

The output will be:

nohup: ignoring input and appending output to ‘nohup.out’
tail -f nohup.out
tail -f nohup.out
killall example.sh

For more information read the manual, it is small and simple but effective.

man nohup

Using screen

You will use a program called screen. Similar programs are: tmux, dtach+dtvm.

screen
├─sshd───sshd───sshd───bash───screen───screen───bash───pstree

./example.sh
[detached from 14691.pts-0.145]
screen -r

Multiple screen sessions

screen command has a lot of options. Reading the manual page will provide you with a wealth of information.

Examples:

Start additional session

Play with these switching commands between the three sessions using control-a and a digit or the control-a control-a sequences

Split screen