How do I stop Android from killing Termux in the background?
To keep Android from stopping Termux in the background, set its battery use to Unrestricted, allow background activity, and use a wake lock when you need a task to keep running with the screen off. These steps help, but they cannot guarantee uninterrupted work: Android can still stop Termux because of low memory, overheating, or extra limits added by your phone’s maker.
Remove Termux’s battery restrictions
Start in Settings → Apps → Termux → Battery. Depending on your Android version, choose Unrestricted, Don’t optimize, or Allow background activity.
Some phones put this setting elsewhere:
- Samsung: Look under Battery → Background usage limits. Remove Termux from sleeping or deep-sleeping apps, and add it to Never auto sleeping apps if available.
- Xiaomi, Redmi, or Poco: Look for No restrictions in Termux’s battery settings and enable Background autostart if available.
- Other brands: Search Settings for “battery optimization,” “background activity,” and “auto launch.”
Names and locations vary. If your recent-apps screen offers a padlock option, locking Termux there may help prevent cleanup tools from closing it. This does not replace the battery settings.
Turn off Battery Saver during testing. Also avoid swiping Termux away or using “clean memory” tools while your task runs.
Keep the processor awake when needed
In Termux, run:
termux-wake-lock
This requests a wake lock, which keeps the processor available while the screen is off. It is useful for tasks that pause when your phone sleeps.
When you finish, release it:
termux-wake-unlock
A wake lock does not prevent Android from killing an app. It also uses more battery, especially if your task continuously uses the processor.
Allow Termux notifications if Android asks, and check for its ongoing session notification. That notification helps you see whether its background service is still active; it is not a guarantee that every command will survive.
Work out what Android is stopping
The symptoms can point you toward the right fix:
- Work pauses with the screen off, then resumes: Sleep or battery restrictions are likely involved.
- Your Termux sessions disappear: Android may have stopped the app or its background service.
- One command ends, but Termux stays open: The command may have crashed, run out of memory, or hit an Android process limit.
Android 12 and newer include restrictions on child processes—programs launched by another app. These are often called “phantom process” limits and can affect Termux, especially when a task starts many separate programs.
Some versions expose a developer option called Disable child process restrictions. Availability varies, and advanced changes through Android’s debugging tools are version-specific. Don’t paste random “fix” commands without checking that they match your Android release.
Keep Termux current using its official installation guidance. Avoid mixing Termux and add-ons from different distribution sources.
Reduce pressure on your phone
Close heavy apps and reduce your task’s workload. For mining, fewer worker threads—separate units of processing work—can reduce heat and memory pressure.
Monero mining is demanding on a phone. A wake lock does not make sustained mining cool, battery-friendly, or profitable. Stop if the phone becomes unusually hot, and never disable thermal protections.
Tools such as tmux can keep work organized when you disconnect from a session, but they cannot preserve it if Android kills the underlying processes.
The bottom line
Start with unrestricted battery use and a wake lock, then test with the screen off. If Termux still stops, check memory pressure and Android’s child-process restrictions rather than adding more battery tweaks.
