Suspend Linux

etienne_marais

Honorary Master
Joined
Mar 16, 2008
Messages
16,250
Reaction score
19,740
Location
Centurion
I am compiling a large application on a VPS via ssh. The compilation may take another 2 minutes or another 2 hours.

Closing the ssh terminal will kill the process, is the suspend then reactivate as background process still a safe route (have not done it in a long time).

ctrl-z
bg 1
 
I suppose it's a moot point, if it does not work I can just continue where it stops and use make &
 
Having said that, is there a way to attach to the process in order to redirect output After reactivation of the suspended process ?

Can 'screen' do that or at least attach to a background process ?
 
Always start a process like that in screen. Easiest and most robust method I've found.
 
Thanks ambo&concentric

A cursory glance at the man pages does not indicate that I can attach to a process already running in the background (pid of tmux client/server can however be specified for certain needs). Will have to make a habit of invoking with screen/tmux from the start when running time consuming processes.
 
Are there any advantages to using screen/tmux as opposed to redirecting stdout and error output (then using tail on a file) when starting up a long running background process ?
 
Are there any advantages to using screen/tmux as opposed to redirecting stdout and error output (then using tail on a file) when starting up a long running background process ?

Well screen you can resume the original session if it required any further interaction.

Outputting to file would be fine if you know the process will end in a certain way.

In which case "nohup command &" should do the job just as well.

Screen has the deeper benefit of running multiple "windows" as such which you can switch between. It's a nice tool if you get into the habit of using it. It also adds a layer of security if you don't want others to see what you were doing.
 
Are there any advantages to using screen/tmux as opposed to redirecting stdout and error output (then using tail on a file) when starting up a long running background process ?

Yes, if the background process is expecting user input and stdout is buffered before being written to fille, then you may not know what input is expected. If you want to log the output of the process you can use -L with screen.
 
Well screen you can resume the original session if it required any further interaction.

Outputting to file would be fine if you know the process will end in a certain way.

In which case "nohup command &" should do the job just as well.

Screen has the deeper benefit of running multiple "windows" as such which you can switch between. It's a nice tool if you get into the habit of using it. It also adds a layer of security if you don't want others to see what you were doing.

Ah, yes, forgot about nohup, have been in the habit of using 'disown'
 
strace -p <pid>
to check process activity
strace -p <pid> -e write
to check output in particular

EDIT: I think -e write dumps all write system calls, may include stdout,stderr,files,streams,other
 
Last edited:
I've got this function in my bashrc to start tmux everytime I use ssh (of course you gotta install tmux on whichever server you're connecting to). Never have to worry about network drops or accidental disconnections.

Code:
function ssh() {
  if [ "$#" == "1" ]; then
    if [ "${1:0:1}" != "-" ]; then
      /usr/bin/ssh "$@" -t 'tmux a || tmux || /bin/bash'
    else
    /usr/bin/ssh "$@";
    fi
  else
    /usr/bin/ssh "$@";
  fi
}

http://www.hamvocke.com/blog/a-quick-and-easy-guide-to-tmux/
 
You could always just use mosh shell.

It allows for disconnects and will just reconnect where you left off.

It also gets rid off stuff like latency when typing. Definitely worth a go!

https://mosh.org/
 
Top
Sign up to the MyBroadband newsletter
X