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?
Either of these actions normally prompts the kernel to hang up on the application, but a nohup wrapper will allow the process to continue. Using the ampersand will run the command in a child process and this child of the current bash session.
Nohup command is used to prevent an important process from being terminated when you log out or close the session. It helps a lot when you are running a process, especially scripts that take a long time to complete.
The nohup command can also be used to run programs in the background after logging off. To run a nohup command in the background, add an & (ampersand) to the end of the command.
Run ping command with nohup command. Re-open the terminal and run pgrep command again. You will get the list of the process with process id which is running. You can stop any background process by running kill command.
Both have there own + and - :
nohup:
screen:
To conclude, both are two different things made with different agendas so comparison is difficult.
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With