Closed V-no-A closed 2 years ago
Do you get anymessages in an adb logcat
when termux is killed?
adb logcat
I'm looking at the logcat.txt file right now but I do not know exactly what I should be looking for since this is my introduction to them.
What should I show you? Everything around the time that I hit Enter? Or everything since I open up Termux up to when I get the "[Process completed (signal 9) - press Enter]
" message?
Something like all messages from when termux is killed and 15 s before and after should be interesting (you could also share the entire log if you are confident it does not contain sensitive information).
What I am curious about is if there is any messages from "android"/"system"/"low memory killer" or something else that indicates that termux is killed, and in that case why.
I don't think any maintainer has a device with android 12 yet, so might be specific for recent android versions
Something like all messages from when termux is killed and 15 s before and after should be interesting (you could also share the entire log if you are confident it does not contain sensitive information).
I'll do the 15 seconds before and after since I'm not confident the entire log won't contain anything I wouldn't want public. I'll show more if needed. Though it'll have to be in 12 hours or so.
I don't think any maintainer has a device with android 12 yet, so might be specific for recent android versions
I'm leaning on it being Android 12 related. Reason I reinstalled Termux was because I got an error on it (cannot recall if it was this same one) right after I updated the phone. I was looking for a reason to change to the F-Droid version from the Google Store and did it immediately without thinking much about the message I got.
Sorry, I was having a hard time getting the error message again.
Since I did not exactly know what to include from the logcat, I created and ran a Python script that writes the time to a txt file. The last written time was "2021-10-29 16:25:52.242" before being interrupted by [Process completed (signal 9) - press Enter]
once again. Here are a few messages at and around that time:
10-29 16:25:50.345 3942 4103 D SharedPreferencesImpl: Time required to fsync /data/user/0/com.weather.Weather/shared_prefs/ALCrashTracker.xml: [<1: 5, <2: 62, <4: 104, <8: 767, <16: 78, <32: 2, <64: 4, <128: 1, <256: 1, <512: 0, <1024: 0, <2048: 0, <4096: 0, <8192: 0, <16384: 0, >=16384: 0]
10-29 16:25:52.246 1664 1834 I ActivityManager: Killing PhantomProcessRecord {4cb7847 6789:17247:python/u0a383}: Trimming phantom processes
10-29 16:25:52.247 1664 1834 I ActivityManager: Killing PhantomProcessRecord {7320874 6756:17247:bash/u0a383}: Trimming phantom processes
10-29 16:25:52.256 1664 1848 I libprocessgroup: Successfully killed process cgroup uid 10383 pid 6789 in 0ms
10-29 16:25:52.257 1664 1848 I ActivityManager: Process PhantomProcessRecord {7320874 6756:17247:bash/u0a383} died
10-29 16:25:52.257 1664 1848 I ActivityManager: Process PhantomProcessRecord {4cb7847 6789:17247:python/u0a383} died
10-29 16:25:52.257 1664 1848 I libprocessgroup: Successfully killed process cgroup uid 10383 pid 6756 in 0ms
10-29 16:26:06.077 3750 4042 I WorkerManager: dispose()
10-29 16:26:13.233 968 1224 I CHRE : @ 9785.504: [ImuCal] [NanoSensorCal:GYRO_RPS] Offset | Temperature [C]: 0.000231, -0.000705, -0.001613 | 38.16
I should've probably mentioned, although wakelock was on, I have gotten the message with it turned off. And, even though this happened while running the Python script, this has happened (like mentioned before) while just having Termux idle:
@V-no-A You should use logcat
within ADB and not under Termux, as the latter will hide information about system activity.
P.S. On Pixel 5 with Android 12 it doesn't get suddenly killed.
@xeffyr I thought I used logcat within ADB. I ran adb logcat > logcat.txt
on Windows and copied and pasted those several lines from the txt file. Can you point me to tutorial of how I am supposed to being doing this?
I ran adb logcat > logcat.txt on Windows
Then ok. But log is still too short, try capturing about 30 lines.
Btw, I'm running now overnight test for this issue, leaving Termux just opened with no utilities running except shell. Screen off, no wakelock, recent apps list cleared.
Android 12 via 15755084
and updated via 5706277f
has added a mechanism to monitor forked child processes started by apps and kills them if they consume too much CPU if app is in background.
Track the child processes that are forked by app processes
Apps could use Runtime.exec() to spawn child process and framework will have no idea about its lifecycle. Now track those processes whenever we find them - currently during the cpu stats sampling they could be spotted. If it's consuming too much CPU while its parent app process are also in the background, kill it.
By default we allow up to 32 such processes; the process with the worst oom adj score of their parents will be killed if there are too many of them.
Check PhantomProcessList
commit history here. The Trimming phantom processes
log entry is from here.
Basically, not a Termux issue and users upgrading to android 12 should expect killing of background processes even from AOSP, like OEM crazy killing wasn't enough.
When you detect the killing, you can run adb logcat -d > logcat.txt
to dump the entire logcat buffer instead of starting realtime monitoring. And are you sure you are not starting some other processes, like a sshd daemon, etc or something else, check ps -ef
.
Then ok. But log is still too short, try capturing about 30 lines.
Will do.
Btw, I'm running now overnight test for this issue, leaving Termux just opened with no utilities running except shell. Screen off, no wakelock, recent apps list cleared.
I think I always had at least 2 other apps in my recent list.
When you detect the killing, you can run
adb logcat -d > logcat.txt
to dump the entire logcat buffer instead of starting realtime monitoring.
Thanks for that. Is it advisable to share the whole logcat or should I actually spend several minutes going through and remove lines that might contain sensitive information?
And are you sure you are not starting some other processes, like a sshd demon, etc or something else, check
ps -ef
.
All I use Termux for is to run Python scripts inside my downloads directory. Here is that message after running ps -ef
and while having 7 other apps opened in the background with the screen turned off (several minutes passed between running ps -ef
and receiving that message):
I haven't looked much at the code, but it seems that 32
process limit may be for phantom processes of all apps combined, so termux processes may get killed even if other apps have background processes running. But even if the limit were to be per app, then even then, termux would still be limited to max 32
processes, which may get killed anytime android decides.
Post output of following to see if there are other phantom processes running. What are your other apps doing?
adb shell "/system/bin/dumpsys activity settings | grep max_phantom_processes"
adb shell "/system/bin/dumpsys activity processes -a"
Or if you want to run from inside termux, first grant one time permissions over adb
. You will require github actions debug build, or wait till v0.118
is released. PACKAGE_USAGE_STATS
was recently requested via 865f29d4, DUMP
was available in v0.109
.
adb shell pm grant com.termux android.permission.PACKAGE_USAGE_STATS
adb shell pm grant com.termux android.permission.DUMP
then run
/system/bin/dumpsys activity settings | grep max_phantom_processes
/system/bin/dumpsys activity processes -a
The -a
flag minimizes the output. The ActivityManagerService
dumps phantom processes list and it should show entries for All Active App Child Processes
and All Zombie App Child Processes
.
$ adb shell "/system/bin/dumpsys activity settings | grep max_phantom_processes"
max_phantom_processes=32
$ adb shell "/system/bin/dumpsys activity processes -a"
...
All Active App Child Processes:
proc #0: PhantomProcessRecord {747692e 7216:6914:bash/u0a147}
user #0 uid=10147 pid=7216 ppid=6914 knownSince=-29m34s22ms killed=false
lastCpuTime=20 timeUsed=+30ms oom adj=0 seq=16
I can reproduce the issue by running following. Sometimes termux gets killed as soon as I run the loop while its still in foreground, sometimes when I switch to another app and come back, and sometimes takes a few minutes. The frequency of sampling for the processes usage is likely the cause, considering that All Active App Child Processes
does not get updated quickly.
for i in $(seq 40); do
sha256sum /dev/zero &
done
You can monitor cpu usage with top
command and run killall sha256sum
to kill the processes started.
Basically, unless this is somehow fixed or exempted, this would be like the end of termux (and tasker) or at least will be very unreliable. This should be reported to google since this is just crazy, possibly crazier than OEM killing.
Edit: It also happens with battery optimizations disabled for termux, don't see any related code either. Adaptive battery disabled too.
Is it advisable to share the whole logcat or should I actually spend several minutes going through and remove lines that might contain sensitive information?
Well that is the question. Its advisable to review it first, but one may not always know what's sensitive.
So based on device_config
shell command for the activity_manager
namespace and max_phantom_processes
key, which when updated, triggers PhantomProcessList.trimPhantomProcessesIfNecessary()
, you can change the behaviour and it might be possible to disable it entirely based on the for
loop in source code by setting max_phantom_processes
to Integer.MAX_VALUE
(2147483647
). The setting seemed to survive on reboot but after a while got set back to default 32
and termux bash
got killed, but maybe it normally resets after reboot, so I set it again. I haven't tested much if it actually works, but seems to be working, but needs more testing, someone should do it on a real device. If it keeps resetting, then that may be a problem. Not sure what (harm) adb shell "/system/bin/device_config set_sync_disabled_for_tests persistent"
would do, it disables syncing, as per modes and used by tests and prevents setting all configs, added in ad3d45a
. State can be checked with adb shell "/system/bin/device_config is_sync_disabled_for_tests"
.
# set value
adb shell "/system/bin/device_config put activity_manager max_phantom_processes 2147483647"
# get value
adb shell "/system/bin/dumpsys activity settings | grep max_phantom_processes"
# or (will be null initially)
adb shell "/system/bin/device_config get activity_manager max_phantom_processes"
Edit: As per below comment, this will only help prevent trimming, processes using excessive CPU will still get killed.
Btw, I'm running now overnight test for this issue, leaving Termux just opened with no utilities running except shell.
Everything went ok, Termux is not killed (expected).
Device info:
Application version:
0.117-gda6174e
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://termux.astra.in.ua/apt/termux-main stable main
Updatable packages:
pcre2/stable 10.39 aarch64 [upgradable from: 10.38]
Android version:
12
Kernel build information:
Linux localhost 4.19.191-gc2161d44afae-ab7624114 #1 SMP PREEMPT Mon Aug 9 09:02:05 UTC 2021 aarch64 Android
Device manufacturer:
Google
Device model:
Pixel 5
Don't see any additional changes in android12-release
branch and I'm using latest avd image sdk_gphone64_x86_64-userdebug 12 SE1A.211012.001 7818354 dev-keys
, which has Nov 5, 2021
patch. Official releases build tags are here.
For more proof its happening, posting detailed info below.
Note that bash
was started with pid
5683
and logcat
logs the killing.
I ActivityManager: Killing PhantomProcessRecord {9ccd0ab 5683:5641:bash/u0a147}: Trimming phantom processes
I libprocessgroup: Successfully killed process cgroup uid 10147 pid 5683 in 0ms
I ActivityManager: Process PhantomProcessRecord {9ccd0ab 5683:5641:bash/u0a147} died
Everything went ok, Termux is not killed (expected).
What's the output for adb shell "/system/bin/dumpsys activity settings | grep max_phantom_processes"
and your build tag. Maybe changes were made for pixel device releases. ~Moreover, revision branches don't exist in aosp repo.~
What's the output for adb shell dumpsys activity settings | grep max_phantom_processes and your build tag.
redfin:/ $ dumpsys activity settings | grep max_phantom_processes
max_phantom_processes=32
Build info:
[ro.build.ab_update]: [true]
[ro.build.characteristics]: [nosdcard]
[ro.build.date]: [Fri Aug 27 06:19:46 UTC 2021]
[ro.build.date.utc]: [1630045186]
[ro.build.description]: [redfin-user 12 SP1A.210812.015 7679548 release-keys]
[ro.build.display.id]: [SP1A.210812.015]
[ro.build.expect.baseband]: [g7250-00147-210811-B-7631450]
[ro.build.expect.bootloader]: [r3-0.4-7617468]
[ro.build.fingerprint]: [google/redfin/redfin:12/SP1A.210812.015/7679548:user/release-keys]
[ro.build.flavor]: [redfin-user]
[ro.build.host]: [abfarm-release-rbe-64-00054]
[ro.build.id]: [SP1A.210812.015]
[ro.build.product]: [redfin]
[ro.build.tags]: [release-keys]
[ro.build.type]: [user]
[ro.build.user]: [android-build]
[ro.build.version.all_codenames]: [REL]
[ro.build.version.base_os]: []
[ro.build.version.codename]: [REL]
[ro.build.version.incremental]: [7679548]
[ro.build.version.min_supported_target_sdk]: [23]
[ro.build.version.preview_sdk]: [0]
[ro.build.version.preview_sdk_fingerprint]: [REL]
[ro.build.version.release]: [12]
[ro.build.version.release_or_codename]: [12]
[ro.build.version.sdk]: [31]
[ro.build.version.security_patch]: [2021-10-05]
Have tried your command with sha256sum /dev/zero
loop and here is what I got:
10-30 13:27:55.958 1702 1970 I ActivityManager: Killing 14231:com.google.android.cellbroadcastreceiver/u0a227 (adj 975): empty #33
10-30 13:28:01.908 1702 2006 I ActivityManager: Killing 14249:com.niksoftware.snapseed/u0a234 (adj 975): empty #33
10-30 13:28:16.766 1702 2010 I ActivityManager: Start proc 18322:com.google.android.apps.carrier.carrierwifi/u0a114 for service {com.google.android.apps.carrier.carrierwifi/com.google.android.wsu.service.WsuServiceImpl}
10-30 13:28:20.478 1702 1970 I ActivityManager: Killing 14312:com.google.android.apps.docs/u0a171 (adj 975): empty #33
10-30 13:28:20.479 1702 1970 I ActivityManager: Killing 14286:com.google.android.documentsui/u0a66 (adj 975): empty #34
10-30 13:28:22.285 1702 4227 I ActivityManager: Killing 14386:com.google.android.deskclock/u0a186 (adj 975): empty #33
10-30 13:28:43.431 1702 1970 I ActivityManager: Killing 14513:com.google.android.apps.wallpaper/u0a197 (adj 995): empty for 1800s
10-30 13:28:46.773 1702 2006 I ActivityManager: Killing 14752:com.google.pixel.livewallpaper/u0a100 (adj 985): empty for 1800s
10-30 13:28:46.774 1702 2006 I ActivityManager: Killing 14581:com.google.android.gm/u0a191 (adj 905): empty for 1801s
10-30 13:28:50.183 1702 3629 I ActivityManager: Killing 14808:com.google.android.calendar/u0a164 (adj 975): empty for 1800s
10-30 13:28:50.184 1702 3629 I ActivityManager: Killing 14832:com.android.providers.calendar/u0a70 (adj 985): empty for 1800s
10-30 13:29:01.799 1702 2009 D ActivityManager: pid 31599 com.google.android.apps.translate received async transactions while frozen
10-30 13:29:01.804 1702 2009 D ActivityManager: sync unfroze 31599 com.google.android.apps.translate
10-30 13:29:01.807 1702 2010 I ActivityManager: Start proc 18517:com.google.android.apps.maps/u0a175 for service {com.google.android.apps.maps/androidx.work.impl.background.systemjob.SystemJobService}
10-30 13:29:05.057 1702 1970 I ActivityManager: Killing 6866:com.cloudflare.onedotonedotonedotone/u0a239 (adj 900): remove task
10-30 13:29:05.133 1702 1970 W ActivityManager: setHasOverlayUi called on unknown pid: 6866
10-30 13:30:37.196 1702 2010 I ActivityManager: Start proc 19085:com.android.externalstorage/u0a73 for content provider {com.android.externalstorage/com.android.externalstorage.ExternalStorageProvider}
10-30 13:30:37.696 1702 2010 I ActivityManager: Start proc 19113:com.google.android.gms.ui/u0a125 for service {com.google.android.gms/com.google.android.gms.chimera.UiIntentOperationService}
10-30 13:30:39.273 1702 2009 I ActivityManager: Deferring FGS notification in legacy app com.kunzisoft.keepass.free/u0a240 : Notification(channel=com.kunzisoft.keepass.notification.channel.database shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0xff43a047 vis=SECRET)
10-30 13:30:51.438 1702 2010 I ActivityManager: Start proc 19386:ua.privatbank.ap24/u0a236 for pre-top-activity {ua.privatbank.ap24/ua.privatbank.ap24v6.MainActivity}
10-30 13:31:12.496 1702 2499 I ActivityManager: PendingStartActivityUids startActivity to updateOomAdj delay:1187ms, uid:10202
10-30 13:31:39.980 1702 2010 I ActivityManager: Start proc 19719:com.android.calllogbackup/u0a62 for broadcast {com.android.calllogbackup/com.android.calllogbackup.CallLogChangeReceiver}
10-30 13:32:12.253 1702 2010 I ActivityManager: Start proc 19857:org.telegram.messenger.web/u0a231 for pre-top-activity {org.telegram.messenger.web/org.telegram.ui.LaunchActivity}
10-30 13:33:16.797 1702 4024 I ActivityManager: PendingStartActivityUids startActivity to updateOomAdj delay:1516ms, uid:10202
10-30 13:33:16.865 1702 2010 I ActivityManager: Start proc 20061:com.android.chrome:sandboxed_process0:org.chromium.content.app.SandboxedProcessService0:108/u0ai33 for {com.android.chrome/org.chromium.content.app.SandboxedProcessService0:108}
Device became laggy and Termux was eventually terminated as well as number of other apps. But no "phantom" processes killed:
130|redfin:/ $ logcat | grep PhantomProcessRecord
^C
130|redfin:/ $
Device became laggy and Termux was eventually terminated as well as number of other apps.
More details about Termux being killed after for i in $(seq 40); do sha256sum /dev/zero & done
: that's only app is terminated and not sha256sum
processes.
Well, you are on android-12.0.0_r1
, latest for Pixel 5 is revision r3
. The r1
has same commit history as r7
. Don't know why its not occurring for you, maybe wait earnestly for an update. ;)
Pixel specific changes could have been made privately. I guess we can ask google for more info.
that's only app is terminated and not sha256sum processes.
~If app got killed, wouldn't sha256sum
have been killed as well.~
Don't see any entry in above log for com.termux
but if app got killed, ideally sha256sum
processes should have too eventually, since they were the real reason for cpu usage, check below comment...
The Killing PhantomProcessRecord...
entry is generated by PhantomProcessRecord.killLocked()
, with the reason Trimming phantom processes
passed by PhantomProcessList.trimPhantomProcessesIfNecessary()
.
The PhantomProcessList.trimPhantomProcessesIfNecessary()
is only trimming processes if more than default 32
exist. It is different from the app or phantom processes being killed if they use excessive CPU, which was done previously too, but only for app process. The ActivityManagerService.updateAppProcessCpuTimeLPr()
and ActivityManagerService.updatePhantomProcessCpuTimeLPr()
handle that and Killing...
log entries will have excessive cpu
reason. Both functions are called by ActivityManagerService.checkExcessivePowerUsage()
. The checking of if a process is using excessive CPU is done by ActivityManagerService.checkExcessivePowerUsageLPr()
. This is done every POWER_CHECK_INTERVAL
, which defaults to 5*60*1000
. But not sure how app CPU usage works when running in emulator, charging was off in emulator settings. I tried running for >5mins
and my host CPU usage was at 100%
(96.0°C
) but processes kept running and didn't see any log entries and neither did battery stats service show "App using battery" notification.
Post output of following to see if there are other phantom processes running. What are your other apps doing?
For this particular instance, I had Google Drive, Google Photos, and Gmail opened in the background; all three not doing anything. Termux was opened on the welcome text. I went to the phone's home screen, turned off screen, came back around two minutes later, opened Termux, and was met with same "Process completed" message.
max_phantom_processes
from adb shell dumpsys activity settings
:
max_phantom_processes=32
``` ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes) OOM levels: -900: SYSTEM_ADJ ( 73,728K) -800: PERSISTENT_PROC_ADJ ( 73,728K) -700: PERSISTENT_SERVICE_ADJ ( 73,728K) 0: FOREGROUND_APP_ADJ ( 73,728K) 100: VISIBLE_APP_ADJ ( 92,160K) 200: PERCEPTIBLE_APP_ADJ ( 110,592K) 225: PERCEPTIBLE_MEDIUM_APP_ADJ ( 129,024K) 250: PERCEPTIBLE_LOW_APP_ADJ ( 129,024K) 300: BACKUP_APP_ADJ ( 221,184K) 400: HEAVY_WEIGHT_APP_ADJ ( 221,184K) 500: SERVICE_ADJ ( 221,184K) 600: HOME_APP_ADJ ( 221,184K) 700: PREVIOUS_APP_ADJ ( 221,184K) 800: SERVICE_B_ADJ ( 221,184K) 900: CACHED_APP_MIN_ADJ ( 221,184K) 999: CACHED_APP_MAX_ADJ ( 322,560K) Process OOM control (74 total, non-act at 11, non-svc at 11): mHomeProcess: ProcessRecord{22364da 21734:com.google.android.apps.nexuslauncher/u0a61} mPreviousProcess: ProcessRecord{1dac4a6 15558:com.termux/u0a383} Process LRU list (sorted by oom_adj, 74 total, non-act at 11, non-svc at 11): All Active App Child Processes: proc #0: PhantomProcessRecord {8f0d7dc 2611:3461:logcat/u0a164} user #0 uid=10164 pid=2611 ppid=3461 knownSince=-1h35m23s39ms killed=false lastCpuTime=10 timeUsed=+20ms oom adj=100 seq=665 proc #1: PhantomProcessRecord {7920e5 3162:3461:logcat/u0a164} user #0 uid=10164 pid=3162 ppid=3461 knownSince=-1h27m21s601ms killed=false lastCpuTime=10 timeUsed=+10ms oom adj=100 seq=665 proc #2: PhantomProcessRecord {1b6f7ba 3253:3461:logcat/u0a164} user #0 uid=10164 pid=3253 ppid=3461 knownSince=-1h27m21s601ms killed=false lastCpuTime=10 timeUsed=+30ms oom adj=100 seq=665 proc #3: PhantomProcessRecord {e3e566b 4120:3461:logcat/u0a164} user #0 uid=10164 pid=4120 ppid=3461 knownSince=-1h26m23s909ms killed=false lastCpuTime=10 timeUsed=+30ms oom adj=100 seq=665 proc #4: PhantomProcessRecord {a195c8 5790:3461:logcat/u0a164} user #0 uid=10164 pid=5790 ppid=3461 knownSince=-1h15m15s965ms killed=false lastCpuTime=10 timeUsed=0 oom adj=100 seq=665 proc #5: PhantomProcessRecord {11fe661 5893:3461:logcat/u0a164} user #0 uid=10164 pid=5893 ppid=3461 knownSince=-1h14m56s494ms killed=false lastCpuTime=10 timeUsed=+10ms oom adj=100 seq=665 proc #6: PhantomProcessRecord {2ccd586 8968:3461:logcat/u0a164} user #0 uid=10164 pid=8968 ppid=3461 knownSince=-41m37s575ms killed=false lastCpuTime=10 timeUsed=+10ms oom adj=100 seq=665 proc #7: PhantomProcessRecord {5e9ee47 9531:3461:logcat/u0a164} user #0 uid=10164 pid=9531 ppid=3461 knownSince=-38m38s396ms killed=false lastCpuTime=10 timeUsed=+10ms oom adj=100 seq=665 proc #8: PhantomProcessRecord {d1e4674 10169:3461:logcat/u0a164} user #0 uid=10164 pid=10169 ppid=3461 knownSince=-28m49s512ms killed=false lastCpuTime=10 timeUsed=0 oom adj=100 seq=665 proc #9: PhantomProcessRecord {113879d 10534:3461:logcat/u0a164} user #0 uid=10164 pid=10534 ppid=3461 knownSince=-28m49s513ms killed=false lastCpuTime=10 timeUsed=0 oom adj=100 seq=665 proc #10: PhantomProcessRecord {910c412 10626:3461:logcat/u0a164} user #0 uid=10164 pid=10626 ppid=3461 knownSince=-28m49s513ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #11: PhantomProcessRecord {fcd27e3 11349:3461:logcat/u0a164} user #0 uid=10164 pid=11349 ppid=3461 knownSince=-21m29s836ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #12: PhantomProcessRecord {91355e0 11406:3461:logcat/u0a164} user #0 uid=10164 pid=11406 ppid=3461 knownSince=-21m29s836ms killed=false lastCpuTime=10 timeUsed=0 oom adj=100 seq=665 proc #13: PhantomProcessRecord {ca60099 12372:3461:logcat/u0a164} user #0 uid=10164 pid=12372 ppid=3461 knownSince=-21m29s836ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #14: PhantomProcessRecord {6330f5e 12666:3461:logcat/u0a164} user #0 uid=10164 pid=12666 ppid=3461 knownSince=-14m56s274ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #15: PhantomProcessRecord {3205f3f 12782:3461:logcat/u0a164} user #0 uid=10164 pid=12782 ppid=3461 knownSince=-14m56s273ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #16: PhantomProcessRecord {b87f00c 13866:3461:logcat/u0a164} user #0 uid=10164 pid=13866 ppid=3461 knownSince=-10m49s764ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #17: PhantomProcessRecord {94d0d55 14132:3461:logcat/u0a164} user #0 uid=10164 pid=14132 ppid=3461 knownSince=-3h58m28s795ms killed=false lastCpuTime=10 timeUsed=+30ms oom adj=100 seq=665 proc #18: PhantomProcessRecord {49cc36a 14317:3461:logcat/u0a164} user #0 uid=10164 pid=14317 ppid=3461 knownSince=-10m49s764ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #19: PhantomProcessRecord {845b05b 14461:3461:logcat/u0a164} user #0 uid=10164 pid=14461 ppid=3461 knownSince=-9m45s82ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #20: PhantomProcessRecord {2ca00f8 14838:3461:logcat/u0a164} user #0 uid=10164 pid=14838 ppid=3461 knownSince=-5m49s707ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #21: PhantomProcessRecord {41e29d1 14910:3461:logcat/u0a164} user #0 uid=10164 pid=14910 ppid=3461 knownSince=-3h57m28s448ms killed=false lastCpuTime=10 timeUsed=+30ms oom adj=100 seq=665 proc #22: PhantomProcessRecord {a3bac36 14938:3461:logcat/u0a164} user #0 uid=10164 pid=14938 ppid=3461 knownSince=-3h57m28s448ms killed=false lastCpuTime=10 timeUsed=+30ms oom adj=100 seq=665 proc #23: PhantomProcessRecord {1a4f737 15447:3461:logcat/u0a164} user #0 uid=10164 pid=15447 ppid=3461 knownSince=-2m53s747ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #24: PhantomProcessRecord {21a34a4 15725:3461:logcat/u0a164} user #0 uid=10164 pid=15725 ppid=3461 knownSince=-1m25s518ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #25: PhantomProcessRecord {c0a920d 15874:3461:logcat/u0a164} user #0 uid=10164 pid=15874 ppid=3461 knownSince=-49s617ms killed=false lastCpuTime=0 oom adj=100 seq=665 proc #26: PhantomProcessRecord {c0e55c2 17826:3461:logcat/u0a164} user #0 uid=10164 pid=17826 ppid=3461 knownSince=-3h29m58s826ms killed=false lastCpuTime=10 timeUsed=+30ms oom adj=100 seq=665 proc #27: PhantomProcessRecord {647cfd3 27443:3461:logcat/u0a164} user #0 uid=10164 pid=27443 ppid=3461 knownSince=-2h11m45s994ms killed=false lastCpuTime=10 timeUsed=+30ms oom adj=100 seq=665 proc #28: PhantomProcessRecord {e17f710 29010:3461:logcat/u0a164} user #0 uid=10164 pid=29010 ppid=3461 knownSince=-2h4m57s282ms killed=false lastCpuTime=10 timeUsed=+40ms oom adj=100 seq=665 proc #29: PhantomProcessRecord {3db4209 30904:3461:logcat/u0a164} user #0 uid=10164 pid=30904 ppid=3461 knownSince=-1h53m27s378ms killed=false lastCpuTime=10 timeUsed=+20ms oom adj=100 seq=665 proc #30: PhantomProcessRecord {e700c0e 31295:3461:logcat/u0a164} user #0 uid=10164 pid=31295 ppid=3461 knownSince=-1h51m7s727ms killed=false lastCpuTime=10 timeUsed=+30ms oom adj=100 seq=665 proc #31: PhantomProcessRecord {a35962f 32065:3461:logcat/u0a164} user #0 uid=10164 pid=32065 ppid=3461 knownSince=-1h50m23s158ms killed=false lastCpuTime=20 timeUsed=+20ms oom adj=100 seq=665 mUidChangeDispatchCount=39302 Slow UID dispatches: com.android.server.job.controllers.QuotaController$QcUidObserver: 0 / Max 4ms android.app.IUidObserver$Stub$Proxy: 0 / Max 8ms android.app.IUidObserver$Stub$Proxy: 0 / Max 6ms android.app.ActivityManager$UidObserver: 0 / Max 5ms android.app.ActivityManager$UidObserver: 0 / Max 11ms android.app.IUidObserver$Stub$Proxy: 1 / Max 161ms android.app.IUidObserver$Stub$Proxy: 0 / Max 10ms com.android.server.AppStateTrackerImpl$UidObserver: 0 / Max 3ms android.app.IUidObserver$Stub$Proxy: 3 / Max 37ms com.android.server.pm.ShortcutService$4: 0 / Max 5ms com.android.server.power.hint.HintManagerService$UidObserver: 0 / Max 14ms com.android.server.usage.UsageStatsService$3: 0 / Max 9ms android.app.ActivityManager$UidObserver: 4 / Max 210ms com.android.server.net.NetworkPolicyManagerService$4: 0 / Max 10ms com.android.server.job.JobSchedulerService$4: 0 / Max 17ms com.android.server.job.controllers.QuotaController$QcUidObserver: 1 / Max 25ms com.android.server.PinnerService$3: 0 / Max 4ms com.android.server.vibrator.VibrationSettings$UidObserver: 0 / Max 5ms mDeviceIdleAllowlist=[1000, 1001, 2000, 10008, 10016, 10022, 10026, 10033, 10041, 10043, 10074, 10164, 10175, 10187, 10199, 10206, 10214, 10281, 10283, 10328, 10383] mDeviceIdleExceptIdleAllowlist=[1000, 1001, 2000, 10008, 10009, 10016, 10018, 10022, 10026, 10033, 10034, 10039, 10041, 10043, 10045, 10052, 10053, 10067, 10074, 10088, 10136, 10152, 10164, 10175, 10187, 10199, 10206, 10214, 10281, 10283, 10328, 10352, 10383] mDeviceIdleTempAllowlist=[10016, 10057] mFgsStartTempAllowList: u0a57: duration=10000 callingUid=u0a57 reasonCode=ALARM_MANAGER_WHILE_IDLE reason=broadcast:u0a57:settings.intelligence.battery.action.PERIODIC_JOB_UPDATE,reason: expiration=2021-10-30 19:00:10.026 (+9s602ms) mForceBackgroundCheck=false ```
logcat.txt sent through email to @agnostic-apollo
10-30 13:57:06.682 1664 1834 I ActivityManager: Killing PhantomProcessRecord {f3f0696 15595:15558:bash/u0a383}: Trimming phantom processes
proc #0: PhantomProcessRecord {8f0d7dc 2611:3461:logcat/u0a164} user #0 uid=10164 pid=2611 ppid=3461 knownSince=-1h35m23s39ms killed=false lastCpuTime=10 timeUsed=+20ms oom adj=100 seq=665
From emailed logcat
W ProcessStats: Tracking association SourceState{f547bc system/1000 BTopFgs #225577} whose proc state 2 is better than process ProcessState{bb30345 com.wsandroid.suite/10164 pkg=com.wsandroid.suite} proc state 3 (33 skipped)
On your device com.termux
package has been assigned the u0a383
user id and com.wsandroid.suite
package has been assigned the u0a164
user id, and the later package is for the McAfee Mobile Security: Antivirus app. All the 32
tracked logcat
PhantomProcessRecord
belong to com.wsandroid.suite
and termux's bash
was one of the processes that got killed. So as mentioned above, the 32
process limit is for all apps combined. If I remember correctly, facebook app also used to run logcat
processes. This will also affect any processes started by Tasker as well.
Try running the adb shell "/system/bin/device_config put activity_manager max_phantom_processes 2147483647"
command as mentioned above and see if that helps prevent trimming, processes using excessive CPU will still get killed.
To check which app a user id belongs to, you can run something like adb shell "/system/bin/dumpsys package | grep -A1 'userId=10164'"
or check here.
It's interesting that some logcat
processes have knownSince=-3h57m28s448ms
(and some for only knownSince=-49s617ms
). I am pretty sure the app normally wouldn't need to run that many processes and is likely "leaking processes", possibly due to failing to stop unneeded ones. I remember one app that had the same problem ;)
Moved phantom process details and how to disable trimming to https://gist.github.com/agnostic-apollo/dc7e47991c512755ff26bd2d31e72ca8 due to lack of heading support in comments.
Issue opened at https://issuetracker.google.com/u/1/issues/205156966
@V-no-A You can try my new xposed module. Please visit https://github.com/dttzyjw0012/PhantomProcessesSavior.
A new patch was just submitted to AOSP titled "add settings to toggle the phantom process monitoring in dev options" just FYI
@MishaalRahmanGH Thanks a lot for notifying. This is indeed great news! I have posted a comment at https://issuetracker.google.com/u/1/issues/205156966#comment27 about it and asked for expected timeline of merger.
Commit has been merged. Jing Ji says "it should be able to make into Android 12L".
https://issuetracker.google.com/u/1/issues/205156966#comment28
Termux version: 0.117 Android version: 12 Device model: Samsung S21 Ultra
same issue all the time making termux completely useless on the device
is there any chance that the issue may be fixed w/o getting root access to the device?
As already detailed in the How to disable the phantom processes killing?
section of the gist referenced in the comment above, run following command with adb
once to prevent phantom processing trimming on Android 12 (at your own risk).
adb shell "/system/bin/device_config set_sync_disabled_for_tests persistent; /system/bin/device_config put activity_manager max_phantom_processes 2147483647"
Disabling device config sync is necessary since gms may reset settings randomly even after boot when update comes. I need to update post.
Even with the workaround to prevent trimming, processes using excessive cpu will be killed. So users will have to limit max cpu usage for commands, like compilation commands. Those issues should be solvable for people on android 12L or 13 by disabling the settings_enable_monitor_phantom_procs
feature flag in developer options, assuming above mentioned commit is merged in aosp release and vendor forks and flag is available. Users with root on android 12 should also be able to disable it with xposed/riru modules.
Users should contact their individual mobile vendors, likely on their support forums and ask them to prioritize merging the 1920354
commit that adds the feature flag in developer options so that its available as soon as possible.
Closing issue since a solution is already available to disable trimming of phantom process for Android 12 and termux can't do anything more about it. Users who upgrade to Android 12 will just have to run the commands over adb/root. I'll look into adding a popup in the app that notifies users about this on update/fresh install and add a "trimmed" termux docs page about this.
The settings_enable_monitor_phantom_procs
flag is available in Pixel Android 12L beta 3 releases (which have been pulled). Unfortunately, feature flags menu won't be available in user build production devices, so users will have to run adb shell settings put global settings_enable_monitor_phantom_procs false
over adb or run setprop persist.sys.fflag.override.settings_enable_monitor_phantom_procs false
with root to disable phantom process trimming and killing of processes using excessive cpu. This is not really user friendly, but it is what it is.
https://twitter.com/MishaalRahman/status/1491487491026833413
https://twitter.com/MishaalRahman/status/1491489385170227205
It's a shame that this project keeps getting limited by changes in android. This app enables so many productivity use cases on android....
Is there a way to get in touch with the AOSP maintainers, or even Google, to have some way to whitelist the app?
😫 android 12 💔 termux, i regret upgrading to android 12
getting signal 9 when installing arch. feelsbadman
It's a shame that this project keeps getting limited by changes in android. This app enables so many productivity use cases on android....
Is there a way to get in touch with the AOSP maintainers, or even Google, to have some way to whitelist the app?
I fully agree with your position - I have used Termux as a prime example of how Android (with Termux) is a much better mobile platform than iOS for programmers/sysadmins/etc.
Termux + nvim/emacs (not going into that debate) makes for an amazing local code editor. Throw in a bluetooth keyboard and you can work from anywhere. If you're SSHing into systems for admin, being able to use the real OpenSSH client is amazing (other SSH apps just don't cut it).
That said, I do understand Google/Android's goals of making the platform more secure. I don't think the Android/Google developers will likely entertain this particular use case (which is unfortunate, since they themselves could probably benefit from it -- but then again, if your device is rooted, you don't necessarily need Termux)
I do think there might be some solutions/workarounds that Termux can implement -- but I'm really not sure. If Android's basic app policy becomes/is "Apps: Do not have any expectations that your App will continue to run in the background, it might be killed at any time"... the solutions for that are pretty limited. The only thing that comes to mind might be some kind of virtualization (which is far from ideal from a performance perspective) that somehow checkpoints/monitors memory (like a "save state") and can restore that when the app relaunches.
Even with phantom process limit bypassed, Termux is still pretty much useless for things like desktop environments as running anything heavier will just kill the entire environment due to "excessive cpu usage". Is there any way to disable the CPU check without resorting to root ? My S22 Ultra stock ROM does not seem to have the setting from 12L to disable monitoring entirely. I hate when the OS tries to play police to "protect" users from buggy apps.
Agree. I'm planning to use Termux with desktop and heavy apps like Blender. Look like it's no more possible since Android 12...
@shim80 Android 12L and likely Android 13 will have an option to disable phantom process killing entirely. I originally planned to use my S22 Ultra with a 14" lapdock for software development, but it looks like I'll have to wait for Android 13.
Android 13 will also bring virtualization with full KVM support, won't it?
It can subject to change anytime, and even Android 13 fully supports it near future. some OEMs may not consider this
What is the best option for running linux with desktop and gpu support for non rooted devices right now?
proot
is the best and only choice
the phantom process limit kill termux when I try to launch desktop through termux-x11
@shim80 Linux has had KVM for ages, it's not that hard (from a technical point of view) to enable on any rooted device with a modern-ish kernel version. Google's KVM demo was a hack-job on a rooted device. Not sure if they will add it to production devices and even if they add it, there's no guarantee it will be user-accessible. But it would sure be nice to be able to boot full OS'es on your phone without root.
@ddscentral I'm more interested running virtual machine through Android than booting full OS'es
@shim80 I meant through KVM obviously. KVM is hardware virtualization which does boot full OS'es.
I'd like to see how Termux will be in Android 13 with a device that has been tested by default on Kernel 5.15 lts and 8gigs of RAM, as Goggle Mandates 8gigs for chrome 64bit. This indeed is pretty noticable in Android Sys. Webview & its behaviour in the ui.
Note :-
Default Android 13 means, from R&D the device was ONLY booted from Droid 13 with EroFS. And not Updated from Abdroid 12.
Hi fellas, has the issue been solved? Android 12 - OneUi 4.1
Following the guide above, and giving trough adb shell some commands(adb shell settings put global settings_enable_monitor_phantom_procs false
), works, but still, sadly, after 1h or 30 minutes, it still gives signal 9...
Regards.
(YES IT'S A MATTER OF JUST ADB SHELL FROM TERMUX, YES YOU CAN MAKE A SHELL SCRIPT TO DO IT, but... Hey am so lazy, call people to clean ass when poop)
Regards.
hi, is there any solution for this problem? I want to try to install another linux, but because of this problem I find it difficult and bother me.
Edit: Check this comment for solution.
Problem description
I get a message saying
[Process completed (signal 9) - press Enter]
at, seemingly, random intervals. Once I press Enter, Termux closes. This may happen while I am running a Python script or simply under the "Welcome to Termux!" text after leaving Termux idle for a while (leaving the app/turning off the screen) and not having run any commands.Steps to reproduce the behavior.
I upgraded my Pixel 3a phone to Android 12 and downloaded Termux from F-Droid as well as Termux:API. I did the
termux-setup-storage
command and gave the app unrestricted battery usage under the Android Apps settings. Lastly, I installed Python usingpkg install python
.What is the expected behavior?
Previously, on Android 11, I had installed Termux from the Google Play Store. Not once did I ever get that
[Process completed (signal 9) - press Enter]
message. I was able to leave Termux running in the background indefinitely.System information