32

Background: I have a long running script that makes database schema changes that has output I would want to check after the migration. I would want to write this to a file.

I have been reading stack overflow about nohup and screen. I have tried both and have concerns about both.

IN: How to run process as background and never die?

They said they used nohup and putty killed the process. How is this possible? I have been unable to replicate using Mac OS X terminal.

With screen I am terrified of typing exit instead of ctrl + a, d

Also If I just quit the terminal app when using screen, it seems to preserve the state.

Screen seems to be the better solution because it is really nifty how you can have a bunch of them open and switch back to the state.

What would you recommend in my situation? I don't have the run the script for another month or so (When I have a release). Should I become more comfortable with screen and just stick with that?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Chris Muench
  • 17,444
  • 70
  • 209
  • 362
  • 2
    nohup is ***extremely*** different than screen. Screen is a terminal multiplexer, or more accurately a terminal-window manager. Nohup is a program that lets you run a program on a remote server without having to worry about whether you `ssh` session hangs up or not. – Alexej Magura Dec 24 '13 at 20:15
  • 1
    I understand the difference, but I can use screen in a way that keeps running even if I quit. I like the fact that it is kind of a way to freeze a terminals state. – Chris Muench Dec 24 '13 at 20:20
  • 3
    For the sake of knowing your options, `tmux` is another terminal mtiplexer like `screen`. I personally use `nohup` for persistent commands beyond the `ssh` session and `tmux` for preserving an environment. – Nicolas De Jay May 06 '14 at 16:41

1 Answers1

40

Both have there own + and - :

nohup:

  1. nohup is good to use for running procs in background when proc don't need any user input like httpd server or any other server proc like that.
  2. nohup does create log in dir of proc execution. log file name default is nohup.out
  3. It avoids proc getting killed due to mistaken ctrl+C , ctrl+D . Just a safe guard.
  4. It's normally installed by default with basic setup. No need to install separately like screen.
  5. It's functionality is very specific to running a job in background and dumping output. Low memory intensive.

screen:

  1. Got to install separately. You can NOT go to a data center or login to
    any box and expect screen is present.
  2. Good to manage multiple terminals on separate subjects and give them name.
  3. Its more of terminal manager and not a command to run a proc for infinite time like nohup.
  4. It's more suitable if proc need user input. Like install
    scripts, yes/no prompts.
  5. With tones of features, comes it's memory. But agreed, some are really great features.

To conclude, both are two different things made with different agendas so comparison is difficult.

Cheers!

mrtipale
  • 869
  • 10
  • 16
  • 5
    I think you got there a typo, you intended to write "You can't go to a datacenter.." instead of "You can go ...". , didn't you? Been 3 years ago, but better late than never, hehe – Patrik Stas Apr 23 '18 at 07:29