Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

From the MongoDB manual:

To start the server as a daemon listening on port 5586 and sending all output to mongodb.log, we can do:

mongod --port 5586 --fork --logpath mongodb.log

What is the benefit to run an application as a daemon and when I should do so?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

If you run MongoDB not forked (also known as a daemon), the instant you close your shell or SSH window, MongoDB will also be shutdown.

The reason why you want to fork it into the background (as a daemon) is so that you are able to continuously run MongoDB separate from your shell, that way it will run without interruption (unless you kill it yourself, or shutdown your computer).

share|improve this answer
    
Is it same as if I run mongod --port 5586 --logpath mongodb.log &? In other word, I use & to force the application run into the background? –  q0987 Oct 31 '11 at 20:10
    
Not entirely, if you use &, it will only be useful to your "session". If it is remote, and you kill your Terminal window, it will also kill Mongo as you are not logged in anymore to keep your background processes in place. If you are using a desktop interface, logging out will also kill this process. –  Steven Lu Oct 31 '11 at 20:14

When you run an application as a daemon, it stays running after you log off of the computer.

This is useful for hosting services from your computer.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.