Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Android 12 Phantom Processes Killed "[Process completed (signal 9) - press Enter]" #2366

Closed
V-no-A opened this issue Oct 29, 2021 · 80 comments

Comments

@V-no-A
Copy link

V-no-A commented Oct 29, 2021

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 using pkg 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

  • Termux application version:
    0.117
  • Android OS version:
    12
  • Device model:
    PIxel 3a
@Grimler91
Copy link
Member

Do you get anymessages in an adb logcat when termux is killed?

@V-no-A
Copy link
Author

V-no-A commented Oct 29, 2021

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?

@Grimler91
Copy link
Member

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

@V-no-A
Copy link
Author

V-no-A commented Oct 29, 2021

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.

@V-no-A
Copy link
Author

V-no-A commented Oct 29, 2021

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:
Screenshot_20211029-025556

@ghost
Copy link

ghost commented Oct 29, 2021

@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.

@V-no-A
Copy link
Author

V-no-A commented Oct 29, 2021

@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?

@ghost
Copy link

ghost commented Oct 29, 2021

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.

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Oct 30, 2021

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.

@V-no-A
Copy link
Author

V-no-A commented Oct 30, 2021

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):
Screenshot_20211029-195259

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Oct 30, 2021

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 865f29d, 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.

dumpsys activity processes log
  All Active App Child Processes:
    proc #0: PhantomProcessRecord {304e913 12355:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12355 ppid=6914 knownSince=-12s230ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #1: PhantomProcessRecord {fcd3750 12356:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12356 ppid=6914 knownSince=-12s230ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #2: PhantomProcessRecord {91b1d49 12357:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12357 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #3: PhantomProcessRecord {2ede64e 12358:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12358 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #4: PhantomProcessRecord {9cb036f 12359:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12359 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #5: PhantomProcessRecord {d56787c 12360:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12360 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #6: PhantomProcessRecord {26f4505 12361:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12361 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #7: PhantomProcessRecord {746195a 12362:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12362 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #8: PhantomProcessRecord {a2e678b 12363:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12363 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #9: PhantomProcessRecord {9d0a068 12364:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12364 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #10: PhantomProcessRecord {7242c81 12365:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12365 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #11: PhantomProcessRecord {cbc7126 12366:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12366 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #12: PhantomProcessRecord {19f167 12367:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12367 ppid=6914 knownSince=-12s229ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #13: PhantomProcessRecord {f435b14 12368:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12368 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #14: PhantomProcessRecord {ae60fbd 12369:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12369 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #15: PhantomProcessRecord {5ee79b2 12370:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12370 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #16: PhantomProcessRecord {14a3d03 12371:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12371 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #17: PhantomProcessRecord {e851480 12372:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12372 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #18: PhantomProcessRecord {5e8eab9 12373:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12373 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #19: PhantomProcessRecord {fc67efe 12374:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12374 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #20: PhantomProcessRecord {8a9a65f 12375:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12375 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #21: PhantomProcessRecord {d66f8ac 12376:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12376 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #22: PhantomProcessRecord {5a47975 12377:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12377 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #23: PhantomProcessRecord {9878d0a 12378:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12378 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #24: PhantomProcessRecord {b6c497b 12379:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12379 ppid=6914 knownSince=-12s228ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #25: PhantomProcessRecord {ba0f398 12380:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12380 ppid=6914 knownSince=-12s227ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #26: PhantomProcessRecord {d5037f1 12381:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12381 ppid=6914 knownSince=-12s227ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #27: PhantomProcessRecord {1996fd6 12382:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12382 ppid=6914 knownSince=-12s227ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #28: PhantomProcessRecord {3ec0257 12383:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12383 ppid=6914 knownSince=-12s227ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #29: PhantomProcessRecord {a7db144 12384:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12384 ppid=6914 knownSince=-12s227ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #30: PhantomProcessRecord {21f622d 12385:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12385 ppid=6914 knownSince=-12s227ms killed=false
      lastCpuTime=0 oom adj=0 seq=48
    proc #31: PhantomProcessRecord {314b362 12386:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=12386 ppid=6914 knownSince=-12s227ms killed=false
      lastCpuTime=0 oom adj=0 seq=48

  All Zombie App Child Processes:
    proc #0: PhantomProcessRecord {244efbb 11686:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=11686 ppid=6914 knownSince=-10m12s335ms killed=true
      lastCpuTime=0 oom adj=0 seq=45
    proc #1: PhantomProcessRecord {98b26d3 11827:6914:sha256sum/u0a147}
      user #0 uid=10147 pid=11827 ppid=69

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.

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Oct 30, 2021

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.

@ghost
Copy link

ghost commented Oct 30, 2021

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).

Screenshot_20211030-095942

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

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Oct 30, 2021

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
Transcript to start 1 bash process + 40 sha256sum processes
~ $ ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
u0_a147   5641   340  5  1970 ?        00:00:02 com.termux
u0_a147   5683  5641  0  1970 pts/0    00:00:00 /data/data/com.termux/files/usr/bin/bash
u0_a147   5728  5683  1  1970 pts/0    00:00:00 ps -ef
~ $ for i in $(seq 40); do sha256sum /dev/zero & done
[1] 5731
[2] 5732
[3] 5733
[4] 5734
[5] 5735
[6] 5736
[7] 5737
[8] 5738
[9] 5739
[10] 5740
[11] 5741
[12] 5742
[13] 5743
[14] 5744
[15] 5745
[16] 5746
[17] 5747
[18] 5748
[19] 5749
[20] 5750
[21] 5751
[22] 5752
[23] 5753
[24] 5754
[25] 5755
[26] 5756
[27] 5757
[28] 5758
[29] 5759
[30] 5760
[31] 5761
[32] 5762
[33] 5763
[34] 5764
[35] 5765
[36] 5766
[37] 5767
[38] 5768
[39] 5769
[40] 5770
~ $
[Process completed (signal 9) - press Enter]
Logcat showing 9 phantom processes trimmed
I ActivityManager: Killing PhantomProcessRecord {9ccd0ab 5683:5641:bash/u0a147}: Trimming phantom processes
I ActivityManager: Killing PhantomProcessRecord {30b2308 5731:5641:sha256sum/u0a147}: Trimming phantom processes
I ActivityManager: Killing PhantomProcessRecord {9a8aa1 5732:5641:sha256sum/u0a147}: Trimming phantom processes
I libprocessgroup: Successfully killed process cgroup uid 10147 pid 5683 in 0ms
I ActivityManager: Killing PhantomProcessRecord {19044c6 5733:5641:sha256sum/u0a147}: Trimming phantom processes
I ActivityManager: Killing PhantomProcessRecord {685cc87 5734:5641:sha256sum/u0a147}: Trimming phantom processes
I libprocessgroup: Successfully killed process cgroup uid 10147 pid 5731 in 0ms
I ActivityManager: Killing PhantomProcessRecord {2b367b4 5735:5641:sha256sum/u0a147}: Trimming phantom processes
I libprocessgroup: Successfully killed process cgroup uid 10147 pid 5732 in 0ms
I ActivityManager: Killing PhantomProcessRecord {9342fdd 5736:5641:sha256sum/u0a147}: Trimming phantom processes
I libprocessgroup: Successfully killed process cgroup uid 10147 pid 5733 in 0ms
I ActivityManager: Killing PhantomProcessRecord {3bbe752 5737:5641:sha256sum/u0a147}: Trimming phantom processes
I libprocessgroup: Successfully killed process cgroup uid 10147 pid 5734 in 0ms
I ActivityManager: Killing PhantomProcessRecord {2e8aa23 5738:5641:sha256sum/u0a147}: Trimming phantom processes
I libprocessgroup: Successfully killed process cgroup uid 10147 pid 5735 in 0ms
I libprocessgroup: Successfully killed process cgroup uid 10147 pid 5736 in 0ms
I libprocessgroup: Successfully killed process cgroup uid 10147 pid 5737 in 0ms
I libprocessgroup: Successfully killed process cgroup uid 10147 pid 5738 in 0ms
I ActivityManager: Process PhantomProcessRecord {9ccd0ab 5683:5641:bash/u0a147} died
I ActivityManager: Process PhantomProcessRecord {2e8aa23 5738:5641:sha256sum/u0a147} died
I init    : Untracked pid 5738 received signal 9
I ActivityManager: Process PhantomProcessRecord {9342fdd 5736:5641:sha256sum/u0a147} died
I ActivityManager: Process PhantomProcessRecord {685cc87 5734:5641:sha256sum/u0a147} died
I ActivityManager: Process PhantomProcessRecord {19044c6 5733:5641:sha256sum/u0a147} died
I init    : Untracked pid 5734 received signal 9
I init    : Untracked pid 5736 received signal 9
I init    : Untracked pid 5733 received signal 9
I ActivityManager: Process PhantomProcessRecord {30b2308 5731:5641:sha256sum/u0a147} died
I init    : Untracked pid 5731 received signal 9
I ActivityManager: Process PhantomProcessRecord {9a8aa1 5732:5641:sha256sum/u0a147} died
I ActivityManager: Process PhantomProcessRecord {2b367b4 5735:5641:sha256sum/u0a147} died
I ActivityManager: Process PhantomProcessRecord {3bbe752 5737:5641:sha256sum/u0a147} died
I init    : Untracked pid 5732 received signal 9
I init    : Untracked pid 5735 received signal 9
I init    : Untracked pid 5737 received signal 9
Remaining 32 tracked phantom processes
  All Active App Child Processes:
    proc #0: PhantomProcessRecord {c1b29f4 5739:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5739 ppid=5641 knownSince=-56s278ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #1: PhantomProcessRecord {511651d 5740:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5740 ppid=5641 knownSince=-56s278ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #2: PhantomProcessRecord {6a51392 5741:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5741 ppid=5641 knownSince=-56s278ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #3: PhantomProcessRecord {52c0163 5742:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5742 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #4: PhantomProcessRecord {1baf160 5743:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5743 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #5: PhantomProcessRecord {2643619 5744:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5744 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #6: PhantomProcessRecord {d7cd6de 5745:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5745 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #7: PhantomProcessRecord {55350bf 5746:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5746 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #8: PhantomProcessRecord {9cdc38c 5747:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5747 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #9: PhantomProcessRecord {8791ad5 5748:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5748 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #10: PhantomProcessRecord {77b82ea 5749:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5749 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #11: PhantomProcessRecord {c7639db 5750:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5750 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #12: PhantomProcessRecord {e598c78 5751:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5751 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #13: PhantomProcessRecord {1bd8f51 5752:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5752 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #14: PhantomProcessRecord {906e3b6 5753:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5753 ppid=5641 knownSince=-56s277ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #15: PhantomProcessRecord {61498b7 5754:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5754 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #16: PhantomProcessRecord {1d6f824 5755:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5755 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #17: PhantomProcessRecord {7facf8d 5756:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5756 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #18: PhantomProcessRecord {5158542 5757:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5757 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #19: PhantomProcessRecord {bd00953 5758:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5758 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #20: PhantomProcessRecord {39d7290 5759:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5759 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #21: PhantomProcessRecord {e51d789 5760:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5760 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #22: PhantomProcessRecord {57ab38e 5761:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5761 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #23: PhantomProcessRecord {5c7e7af 5762:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5762 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #24: PhantomProcessRecord {f0f27bc 5763:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5763 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #25: PhantomProcessRecord {ef76345 5764:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5764 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #26: PhantomProcessRecord {bf27a9a 5765:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5765 ppid=5641 knownSince=-56s276ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #27: PhantomProcessRecord {4b54fcb 5766:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5766 ppid=5641 knownSince=-56s275ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #28: PhantomProcessRecord {18503a8 5767:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5767 ppid=5641 knownSince=-56s275ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #29: PhantomProcessRecord {8afeec1 5768:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5768 ppid=5641 knownSince=-56s275ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #30: PhantomProcessRecord {7eda666 5769:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5769 ppid=5641 knownSince=-56s275ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
    proc #31: PhantomProcessRecord {1c71da7 5770:5641:sha256sum/u0a147}
      user #0 uid=10147 pid=5770 ppid=5641 knownSince=-56s275ms killed=false
      lastCpuTime=0 oom adj=0 seq=13
App and Device Info

Termux App Info

APP_NAME: Termux
PACKAGE_NAME: com.termux
VERSION_NAME: 0.117
VERSION_CODE: 117
UID: 10147
TARGET_SDK: 28
IS_DEBUGGABLE_BUILD: true
APK_RELEASE: Github
SIGNING_CERTIFICATE_SHA256_DIGEST: B6DA01480EEFD5FBF2CD3771B8D1021EC791304BDD6C4BF41D3FAABAD48EE5E1

Device Info

Software

OS_VERSION: 5.10.43-android12-9-00031-g02d62d5cece1-ab7792588
SDK_INT: 31
RELEASE: 12
ID: SE1A.211012.001
DISPLAY: sdk_gphone64_x86_64-userdebug 12 SE1A.211012.001 7818354 dev-keys
INCREMENTAL: 7818354
SECURITY_PATCH: 2021-11-05
IS_DEBUGGABLE: 1
IS_EMULATOR: 1
IS_TREBLE_ENABLED: true
TYPE: userdebug
TAGS: dev-keys

Hardware

MANUFACTURER: Google
BRAND: google
MODEL: sdk_gphone64_x86_64
PRODUCT: sdk_gphone64_x86_64
BOARD: goldfish_x86_64
HARDWARE: ranchu
DEVICE: emulator64_x86_64_arm64
SUPPORTED_ABIS: x86_64, arm64-v8a

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.

@ghost
Copy link

ghost commented Oct 30, 2021

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]

@ghost
Copy link

ghost commented Oct 30, 2021

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:/ $

@ghost
Copy link

ghost commented Oct 30, 2021

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.

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Oct 30, 2021

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...

@agnostic-apollo agnostic-apollo changed the title [Bug]: Getting "[Process completed (signal 9) - press Enter]" when idle or while running Python script. [Bug]: Android 12 Phantom Processes Killed "[Process completed (signal 9) - press Enter]" Oct 30, 2021
@agnostic-apollo agnostic-apollo pinned this issue Oct 30, 2021
@agnostic-apollo
Copy link
Member

agnostic-apollo commented Oct 30, 2021

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.

@V-no-A
Copy link
Author

V-no-A commented Oct 30, 2021

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

adb shell /system/bin/dumpsys activity processes -a

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

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Oct 30, 2021

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.

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Oct 30, 2021

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 ;)

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Nov 4, 2021

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.

mcafee-logcat.txt

@agnostic-apollo
Copy link
Member

Issue opened at https://issuetracker.google.com/u/1/issues/205156966

@dttzyjw0012
Copy link

@V-no-A You can try my new xposed module. Please visit https://github.com/dttzyjw0012/PhantomProcessesSavior.

@MishaalRahmanGH
Copy link

A new patch was just submitted to AOSP titled "add settings to toggle the phantom process monitoring in dev options" just FYI

@agnostic-apollo
Copy link
Member

@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.

@agnostic-apollo
Copy link
Member

Don't either of you have access to a pc? Run over adb usb if you can't figure out wireless way. And the pairing prompt must not be dismissed while pairing, use split screen.

adb shell settings put global settings_enable_monitor_phantom_procs false

That command is not for android 12, read #2366 (comment)

@xx1182

This comment was marked as off-topic.

@Mohammediraqi7

This comment was marked as off-topic.

@sylirre
Copy link
Member

sylirre commented Sep 18, 2022

nc -vz 192.168.1.110:35699

Correct NetCat usage syntax is:

nc -vz 192.168.1.110 35699

Make sure the pairing dialog was not dismissed (closed or disappeared) at the time when you are pairing or running this nc command.

How to pair and connect to Wireless ADB on same device without PC:

screen-20220918-094304.2.mp4

To my Knowledge you can set the App as a "game" so it has less limitations... Or include the maximum number of processes termux can make into the source

This is not true in case of phantom processes. Their limit is system-wide and works against all apps in summary. You can't override it with an application config but can change it through the ADB or root shell.

@hideandseekstheorder

This comment was marked as duplicate.

shrihankp pushed a commit to reisxd/termux-app that referenced this issue Oct 20, 2022
…HANTOM_PROCS value in about page

MONITOR_PHANTOM_PROCS will only be shown in Android 12+ devices and will be marked "<unsupported>" if its not supported in current android build. It will show in Termux Settings->About->Device Info->Software and in reports. Flag is available on Pixel Android 12L beta 3 and Android 13. Check FeatureFlagUtils for more details.

Getting supported feature flags and their values is done through reflection on android "android.util.FeatureFlagUtils" class and requires bypassing android hidden API restrictions.

Related issue termux#2366
https://issuetracker.google.com/u/1/issues/205156966#comment27
@ghost

This comment was marked as off-topic.

@Poojanil

This comment was marked as off-topic.

@Poojanil

This comment was marked as off-topic.

@Macwilson007

This comment was marked as off-topic.

@termux termux deleted a comment from Macwilson007 Nov 24, 2022
@Grimler91

This comment was marked as off-topic.

@termux termux deleted a comment from twaik Feb 3, 2023
@termux termux deleted a comment from Inginirnaqeebullah Feb 3, 2023
@termux termux deleted a comment from twaik Feb 3, 2023
@termux termux deleted a comment from Inginirnaqeebullah Feb 3, 2023
@agnostic-apollo

This comment was marked as off-topic.

@termux termux deleted a comment from omarralll Mar 8, 2023
@termux termux deleted a comment from ISLAM-66 Mar 8, 2023
@termux termux deleted a comment from sgtroy88 Mar 8, 2023
@termux termux locked as resolved and limited conversation to collaborators Mar 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests