Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

nmmain self-daemonizing is memory inefficient #117

@aaaaalbert

Description

@aaaaalbert

Unless instructed otherwise via the --foreground command-line flag, the nodemanager automatically daemonizes after starting up. This puts it in the background and decouples it from the controlling terminal (if any). (Otherwise, running start_seattle.sh or python nmmain.py and later closing the terminal would kill the nodemanager.)

In order to daemonize, the nodemanager fork()s twice and redirects its stdstreams from / to /dev/null effectively. Only the latter of the forked children is kept alive, the parent and first child processes both exit.

On systems with small amounts of available memory such as WiFi routers running OpenWrt, fork()ing is problematic: The parent nodemanager process consumes significant amounts of RAM already, and RAM consuption increases linearly with every fork as a copy of the parent process' memory image is created. Due to the typically low CPU speed of these devices, this transient spike in RAM consumption can lock up the system for minutes, or even cause memory exhaustion which crashes the nodemanager.


An immediate solution would be to not self-daemonize, but rather use common POSIX tools to achieve the same thing:

nohup python nmmain.py </dev/null >/dev/null 2>&1 &

(nohup disables signal forwarding from the terminal to the process, the <, > redirect stdin and stdout so that the process doesn't read from or write to the terminal anymore, 2>&1 redirects stderr into the already-redirected stdout, and & puts the whole thing in the background).

This snippet would render self-daemonizing in nmmain.py unneccessary, and would replace backgrounding without detaching in the Seattle start shell script.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions