A follow-up of the previous post about the screen command.
less memory than
screen, that is the price to pay for all those nice features that come with
screen must be installed as a separate package while
nohup usually is distributed as
part of core utilities in almost any Linux distribution. However, if you need to run scripts that accept parameters then
screen will make your life easier.
They are different tools and difficult to compare. The best thing to do is understand both of them and use the right one depending on your case.
nohup is a command that I’ve found in every Linux distribution that I’ve worked with. It was present also in Solaris
and BSD systems that I worked with a few years ago. You can be confident that when you open a terminal in any Linux
nohup command will be there. Let’s have a look at some major Linux distributions:
- Ubuntu and debian
include the command in the
coreutilspackage, which is a fundamental part of the operating system.
OpenSuse also provide
nohupcommand as part of their
- Even busybox which is a tool that provides a fairly complete environment for any small or
embedded linux systems includes the
nohupcommand by default.
nohup also comes installed in macOS, which it’s not surprising at all given that macOS is based on BSD.
On the contrary,
screen must be installed as a separate package. This means that you might stumble upon machines in
which it’s not installed. For example, I still have access to a shared hosting server that you could access using ssh. I had
a very limited amount of linux commands available and
screen was not one of them. But you know what?
nohup is installed there!
For this reason, it’s a good idea to know how
nohup works and what you can and can’t do with it. It will be like
that good old friend that you know since kindergarten… it will always be there for you.
nohupwill always be there so my suggestion is that you should learn how to use it.
nohup is good for running processes in the background when those processes don’t require user input. For
example, let’s make a backup of our user folder using
> nohup tar cfj /tmp/mybackup.tar.bz2 /home/myuser & appending output to nohup.out >
Processes that don’t require user input are great to use with
However, if the process requires user input, then
screen it’s better for the task. As an example,
we still have a Jira Server intallation in my current project.
We have a documented procedure to upgrade our instances when a new Jira version is released and that procedure
involves a script that asks you different questions during the upgrade process. We use
screen for that.
Using screen we can start the Jira upgrade process, answer whatever questions the upgrade script asks and let it work for
some time in the background while it performs the backups and other stuff. We can even close the ssh connection to the
server. Later, we can ssh back to the server, reattach to the screen and continue with the last part of the installation.
I can’t do that with
Terminal window manager
screen is good to manage multiple terminals. For example, you can open a terminal to do some backups and another
terminal to configure your nginx server, all of this with one ssh connection. You can give them a meaningful name
-S option and switch from one to another:
> screen -s backups tar cfpj /tmp/backup.tar.bz2 /home/myuser (detach with CTRL+A d) > screen -s nginx_config (detach with CTRL+A d) > screen -ls There are screens on: 16531.nginx_config (Detached) 16507.backups (Detached)
It’s more a terminal manager while
nohup is a tool to run processes in the background detached from the terminal.
Answering the question in the title of this post: there is no tool better than the other one.
screen are different things and therefore difficult to compare. Being a terminal manager,
screen is more powerful
and it’s a great add-on to your toolset if you work regularly with the command line. However, the availability of
makes it almost a universal tool, so it’s good to know what you can and can’t do with it just in case you stumble upon
a system in which no terminal manager like
screen can be installed.