Mongo logpath fork require

Hi All,

I neve able to understand why fork option is required for logpath parameter. I am not able to udnerstand relation between these 2.

Hi @Jayshree_Gyanchandani and welcome to the MongoDB Community forums.

You can have a logPath set without using fork. This will leave the process running in the foreground (you will not get returned to your operating system prompt). Doing this, the current terminal will appear to be frozen as you won’t see any output. Since the process is running in the foreground, you will need to press ctrl+c to stop the process and return to an operating system prompt.

However, if you fork the process, you are then putting the process into the background (it will keep running and will return you to a system prompt). In this case a logPath is needed so MongoDB has a location to write the log files to since there’s no guarantees that the terminal that started the process will continue to keep running.

If you don’t supply either logPath or fork, then the mongod process will continue to run in the current terminal window until ctrl+c has been pressed (or the terminal window is shutdown). In this case the mongod process will log to the stdOut handle which is generally the terminal window that was used to start the mongod process.

Let us know you have other questions.


Thanks @Doug_Duncan. So in case of fork process, how to stop mongod process if we will not use ctrl + c.

If you only have a single mongod process running on your system, which should be the case for a production system, you could run pkill mongod. This command will kill any mongod process running on your system, so if you have multiple mongod processes running it will kill all of them.

If you have multiple mongod process running (for example on a test system), you would run ps -ef | grep mongod. This will give you all of the PIDs that are running the mongod process. From there you would run kill xxx (where xxx is the PID from the earlier command for the process you want to kill).

1 Like

Thank you so much @Doug_Duncan :slight_smile: You have explained in a very simple way that’s easy to understand. Will be back again some more questions soon :slight_smile:


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.