4

I am running a big julia simulation in AWS machine (linux). I use putty to run from the command line.

I type: julia myscript.jl

However, whenever I close the command prompt, or putty or my laptop, the run on the AWS server will stop. I wonder if anyone knows is there a way to keep julia running when I close the command line prompt. As I do not want to keep my laptop open and putty stay connected for several days

Thanks

David Sainez
  • 6,446
  • 1
  • 22
  • 45
Ben
  • 43
  • 2
  • 3
    `nohup julia myscript.jl &` – FoggyDay Jan 12 '20 at 06:07
  • 1
    you can run that command in `screen`. For more details, refer [this](https://www.geeksforgeeks.org/screen-command-in-linux-with-examples/) URL – Nitish Jan 12 '20 at 06:25
  • 2
    I want to throw tmux into the ring. Depending on your scenario a SystemD service would also be a good solution – Marged Jan 13 '20 at 00:42
  • This has been asked zillion times here already. For example: [How to make a programme continue to run after log out from ssh?](https://stackoverflow.com/questions/954302/how-to-make-a-programme-continue-to-run-after-log-out-from-ssh) + Not to mention that such question are actually off-topic on [so]. – Martin Prikryl Jan 13 '20 at 09:32
  • @Ben - you're welcome :) – FoggyDay Jan 14 '20 at 07:14

1 Answers1

1

dtach exists for this purpose. It will keep a process alive even if the terminal session that created the process is closed.

Once you log in through ssh, start a new dtach session:

$ dtach -A /tmp/my-dtach-session julia myscript.jl

Then detach from the session with ctrl+\.

Detaching will not kill your process. Here I check that it is still running after detaching:

[david@blue ~] $ ps aux | grep dtach                                       
david      506  0.0  0.0   8460  1484 ?        Ss   16:15   0:00 dtach -A /tmp/my-dtach-session ./pkg/julia-1.3.0/bin/julia
david      517  0.0  0.0   6140  2224 pts/2    S+   16:16   0:00 grep dtach

After you detach, you can close your ssh session like normal. If your process has not finished, you can log back in and reattach:

$ dtach -a /tmp/my-dtach-session 
David Sainez
  • 6,446
  • 1
  • 22
  • 45