mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Linux

Reply
 
Thread Tools
Old 2021-04-22, 14:20   #1
bur
 
bur's Avatar
 
Aug 2020
79*6581e-4;3*2539e-3

42410 Posts
Default 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?
bur is offline   Reply With Quote
Old 2021-04-22, 14:29   #2
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

22·7·359 Posts
Default

Quote:
Originally Posted by bur View Post
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...
chalsall is online now   Reply With Quote
Old 2021-04-22, 15:13   #3
Nick
 
Nick's Avatar
 
Dec 2012
The Netherlands

33418 Posts
Default

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.
Nick is offline   Reply With Quote
Old 2021-04-22, 21:01   #4
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

2×29×71 Posts
Default

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.
EdH is offline   Reply With Quote
Old 2021-04-23, 01:17   #5
masser
 
masser's Avatar
 
Jul 2003
Behind BB

23×13×17 Posts
Default

I use "disown" - but I'm interested to hear better alternatives.
masser is offline   Reply With Quote
Old 2021-04-23, 02:45   #6
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

2×29×71 Posts
Default

Quote:
Originally Posted by masser View Post
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.
EdH is offline   Reply With Quote
Old 2021-04-23, 04:26   #7
Batalov
 
Batalov's Avatar
 
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2

2·4,813 Posts
Thumbs up

Quote:
Originally Posted by masser View Post
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.
Batalov is offline   Reply With Quote
Old 2021-04-23, 06:56   #8
bur
 
bur's Avatar
 
Aug 2020
79*6581e-4;3*2539e-3

23×53 Posts
Default

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 > ... :)
bur is offline   Reply With Quote
Old 2021-04-23, 07:02   #9
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

3·5·263 Posts
Default

Quote:
Originally Posted by bur View Post
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?
paulunderwood is offline   Reply With Quote
Old 2021-04-23, 14:13   #10
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

1005210 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
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.
chalsall is online now   Reply With Quote
Old 2021-04-23, 15:35   #11
masser
 
masser's Avatar
 
Jul 2003
Behind BB

23·13·17 Posts
Default

Quote:
Originally Posted by EdH View Post
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.
masser is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is LMH > 100M still alive? TheMawn LMH > 100M 25 2016-04-18 16:11
Old pentium bug still alive? ATH Soap Box 8 2010-04-14 00:48
How do I logoff without clearing the cookies? retina Forum Feedback 12 2006-11-12 07:53
Processes cleanup JuanTutors Software 2 2004-07-06 14:34
Windows XP logoff sometimes kills Prime95 markhl Software 8 2003-07-07 16:00

All times are UTC. The time now is 10:13.


Tue Dec 7 10:13:58 UTC 2021 up 137 days, 4:42, 0 users, load averages: 1.28, 1.31, 1.38

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.