mersenneforum.org Keeping processes alive after logoff
 User Name Remember Me? Password
 Register FAQ Search Today's Posts Mark Forums Read

 2021-04-22, 14:20 #1 bur     Aug 2020 79*6581e-4;3*2539e-3 2·199 Posts Keeping processes alive after logoff I have a headless machine that I only access via SSH. I'm currently using tmux to keep yafu/cado etc running after I log off. Is that the best choice here?
2021-04-22, 14:29   #2
chalsall
If I May

"Chris Halsall"
Sep 2002
Barbados

23·17·73 Posts

Quote:
 Originally Posted by bur Is that the best choice here?
There are many options for this kind of thing, including "nohup", "session" etc.

Personally I just do something like "mprime -d >> mprime.log < /dev/null 2> /dev/null &" and then exit. This redirects STDIN, STDOUT, and STDERR so there are no file handles attached to the console, and so mprime continues its work without any problems.

Last fiddled with by chalsall on 2021-04-22 at 15:11 Reason: s/mprime >/mprime -d >>/; # Good to actually have mprime output something to log...

 2021-04-22, 15:13 #3 Nick     Dec 2012 The Netherlands 22×3×5×29 Posts In general, the concepts to be aware of here are process groups, sessions and controlling terminals. Code: man 7 credentials is one place to start.
 2021-04-22, 21:01 #4 EdH     "Ed Hall" Dec 2009 Adirondack Mtns 2×1,999 Posts I have a headless "farm" and I use tmux for terminal type use. There is also a similar option called "screen" that works the same. For my use, I have a GUI session start and use VNC over SSH to log into the GUIs of the machines. The machines are completely headless and use an Xorg dummy setup to make the desktop machines all the same resolution. The GUI and VNC via SSH do tax the machines a little, but I like to have several terminals open in some of the GUIs.
 2021-04-23, 01:17 #5 masser     Jul 2003 wear a mask 6C016 Posts I use "disown" - but I'm interested to hear better alternatives.
2021-04-23, 02:45   #6
EdH

"Ed Hall"
Dec 2009
Adirondack Mtns

2×1,999 Posts

Quote:
 Originally Posted by masser I use "disown" - but I'm interested to hear better alternatives.
As the OP and I mentioned, "tmux" will allow you to open a terminal that can be left running when you close the calling terminal. Basically, it works like this:

Open a terminal in the GUI or via SSH, etc.
Enter "tmux" (without quotes).
Start your program at the tmux prompt.
Use CTRL+b, then d (without the CTRL) to exit tmux and leave the called process running. (It will say that it detached.)
You can then close your calling terminal.

To get back into the session, use "tmux a" in a terminal.
To close the tmux session, use "exit." (It will say that it exited.)

"screen" works very much the same way and both have a lot more functionality, as described in their docs, such as multiple panes within a session.

2021-04-23, 04:26   #7
Batalov

"Serge"
Mar 2008
Phi(4,2^7658614+1)/2

255A16 Posts

Quote:
 Originally Posted by masser I use "disown" - but I'm interested to hear better alternatives.
disown -a is just as good as not forgetting to add nohup some short time ago.

"just do it" (as often as you want) and you will be golden.

 2021-04-23, 06:56 #8 bur     Aug 2020 79*6581e-4;3*2539e-3 2·199 Posts Ok thanks, I'll keep using tmux for now. This mprime -d >> mprime.log < /dev/null 2> /dev/null & seems elegant in that it doesn't rely on any other additional software. I have to admit I don't understand half of the > ... :)
2021-04-23, 07:02   #9
paulunderwood

Sep 2002
Database er0rr

3,853 Posts

Quote:
 Originally Posted by bur Ok thanks, I'll keep using tmux for now. This mprime -d >> mprime.log < /dev/null 2> /dev/null & seems elegant in that it doesn't rely on any other additional software. I have to admit I don't understand half of the > ... :)
> is redirect output to
>> is append output to
< get input from

2 is std error?

2021-04-23, 14:13   #10
chalsall
If I May

"Chris Halsall"
Sep 2002
Barbados

992810 Posts

Quote:
 Originally Posted by paulunderwood 2 is std error?
Yup. 2> is STDERR, while > is STDOUT.

I could have also done "2>&1" to redirect STDERR to STDOUT, but I tend not to use that because it is less obvious what's going on, and it uses the "&" symbol which is used later in the command string to throw the process into the background.

Last fiddled with by chalsall on 2021-04-23 at 14:33 Reason: Corrected small error.

2021-04-23, 15:35   #11
masser

Jul 2003
wear a mask

33008 Posts

Quote:
 Originally Posted by EdH Open a terminal in the GUI or via SSH, etc. Enter "tmux" (without quotes). Start your program at the tmux prompt. Use CTRL+b, then d (without the CTRL) to exit tmux and leave the called process running. (It will say that it detached.) You can then close your calling terminal. To get back into the session, use "tmux a" in a terminal. To close the tmux session, use "exit." (It will say that it exited.)
Many thanks, EdH. You too, Batalov. I just went through the sequence above (had to install tmux first) and it works great.

 Thread Tools

 Similar Threads Thread Thread Starter Forum Replies Last Post TheMawn LMH > 100M 25 2016-04-18 16:11 ATH Soap Box 8 2010-04-14 00:48 retina Forum Feedback 12 2006-11-12 07:53 JuanTutors Software 2 2004-07-06 14:34 markhl Software 8 2003-07-07 16:00

All times are UTC. The time now is 16:21.

Sun Oct 17 16:21:56 UTC 2021 up 86 days, 10:50, 1 user, load averages: 1.06, 1.05, 1.04

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.