In the past, I've used nohup to run big background jobs, but I've noticed that a lot of people use screen in this context. Does screen provide some kind of functional advantage that I am unaware of, or is it just a matter of preference?
Asked
Active
Viewed 4.5k times
51
HalosGhost
- 4,732
- 10
- 33
- 41
4 Answers
35
Both have their own plusses and minuses:
nohup:
- nohup is good to use for running processes in the background when the processes don't need any user input, like a web server or any other server process like that.
- nohup does create log in the directory of process execution.
The log file name
is
nohup.out. - It avoids the process getting killed due to mistaken Ctrl+C or similar key combination. Just a safeguard.
- It's normally installed by default with basic setup. No need to install separately like screen.
- Its functionality is very specific to running a job in background and dumping output. Low memory intensive.
screen:
- Got to install separately. You cannot go to a data center or login to any box and expect screen is present.
- Good to manage multiple terminals on separate subjects and give them names.
- Its more of terminal manager and not a command to run a process for infinite time like nohup.
- It's more suitable if the process needs user input. Like install scripts, yes/no prompts.
- With tons of features, comes its memory. But agreed, some are really great features.
@rahmu, I will never guess pid if want to kill it. Be sure before killing someone/something ;) .
Best way in both cases for screen and nohup is:
ps -eaf | grep "nohup" | grep "your proc name/keyword".
Use screen and check what is running on it.
To conclude, they are two different things made with different agendas, so comparison is difficult.
G-Man Says 'Reinstate Monica'
- 22,130
- 27
- 68
- 117
mrtipale
- 459
- 5
- 5
24
screen has a ton of features. It doesn't just "daemonize" a process, it's more of a window manager for terminals.
It can be used if the process needs input at some point, you can go and check the process's output, reconnect to its terminal, ...
So no, it's not just a matter of preference, they are not the same thing at all.
-
4You can check the output with `nohup [...] > fileName.log 2>&1` as well. Plus that means that the output is not lost. – Sardathrion - against SE abuse Nov 16 '11 at 08:12
-
1I like that description of screen: "a window manager for terminals"! – rickumali Nov 16 '11 at 12:04
11
screen lets you:
- come back to the actual running screen, send signals, see how fast it goes, see whether there are error messages etc..
- name processes with a meaningful title. if you want to kill one process you don't have to do a guess work about its process id.
-2
- process progress can be checked also by
nohupby database fields debug. ps ax | grep nohupwill show you the id of the process and you can kill it.nohupis faster. The simple reason is that it depends on the internet connection between your PC and the server. Whenever the internet goes slow, the process goes slow as well.
-
3
-
1
-
#2 will show process to kill only if there's only one nohup process is running. Else, it will show multiple. In either case, point 2 is not entirely incorrect. – Anil_M Sep 03 '19 at 06:12
-
I find 3 to be surprising. how does the internet speed affect the process speed at all? – asgs May 08 '20 at 16:49