Benjamin-Loison / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
0 stars 0 forks source link

[Bug]: Too many pending processes maybe due to `crontab` #44

Open Benjamin-Loison opened 5 days ago

Benjamin-Loison commented 5 days ago

Problem description

ps aux | wc -l
1708
crontab -l
Output: ``` #* * * * * THRESHOLD=200; NB=$(ps aux | wc -l); if [ $NB -gt $THRESHOLD ]; then termux-notification -t "ps aux is detected as reporting too many jobs ($NB compared to $THRESHOLD)"; fi #* * * * * cd bens_folder/termux/ && ./ps-check.py ... ```

32 jobs after killing all idling termux-battery-status executions Note that executing this crontab may involve additional jobs.

ps-check.py: ```python #!/usr/bin/python3 import subprocess def execute(cmd): return subprocess.check_output(cmd, shell=True).decode('utf-8')[:-1] cmd = 'ps aux | wc -l' #cmd = 'ps aux | grep python3 | wc -l' result = execute(cmd) pythonInstances = int(result) n = 50 if pythonInstances > n: execute(f'termux-notification -t "More than {n} python instances have been detected"') ```

Steps to reproduce the behavior.

Not read.

What is the expected behavior?

No response

System information

Benjamin-Loison commented 5 days ago
ps aux | grep ' CROND -n -s$' | wc -l
237

1708 / 327 = 5.22

ps aux | grep ' jq .temperature$' | wc -l
123
ps aux | cat

helps seeing the actual whole line.

ps aux | grep ' /data/data/com.termux/files/usr/libexec/termux-api BatteryStatus$' | wc -l
237
ps aux | grep ' /data/data/com.termux/files/usr/bin/sh /data/data/com.termux/files/usr/bin/termux-battery-status$' | wc -l
237

well enumerating the processes is not very interesting should focus on solving one.

Benjamin-Loison commented 5 days ago

App info of Termux and Termux API do not seem to show possible background issues.

Benjamin-Loison commented 5 days ago

It seems that:

crontab -l
* * * * * (date && termux-battery-status | jq .temperature && cat /sys/class/thermal/thermal_zone*/temp 2> /dev/null) >> bens_folder/termux/temperature.txt
* * * * * (date && termux-battery-status) >> bens_folder/termux/battery.txt

are to blame.

Benjamin-Loison commented 5 days ago
time (date && termux-battery-status | jq .temperature && cat /sys/class/thermal/thermal_zone*/temp 2> /dev/null)
Output: ``` Thu Oct 17 01:02:30 CEST 2024 31.399999618530273 37000 37976 79 37000 0 0 0 -274000 -274000 -274000 32000 31000 468 -273000 -273000 -273000 -273000 37000 40000 41000 -273000 625 -273000 -273000 -273000 -273000 -40000 -40000 42800 45100 44100 3836 45400 43800 44100 43800 45100 44800 45100 44500 45100 44800 3836 42200 41900 43200 44500 43500 43500 43800 42900 40600 40600 3836 41900 42500 43800 42900 42500 44800 44100 45400 44100 44500 0 44100 44800 44500 44800 44800 43500 37629 31024 39007 39268 0 38305 39487 33136 31810 38374 43800 40900 40600 41900 42500 0 41900 41900 40600 40900 31500 31400 real 0m0.413s user 0m0.028s sys 0m0.083s ```
Benjamin-Loison commented 5 days ago
time (date && termux-battery-status)
Output: ``` Thu Oct 17 01:03:10 CEST 2024 { "health": "GOOD", "percentage": 79, "plugged": "UNPLUGGED", "status": "DISCHARGING", "temperature": 31.299999237060547, "current": -797730 } real 0m0.358s user 0m0.030s sys 0m0.047s ```

so it is unclear why both kind of tasks are not executed right now at least as running one of each works fine quickly. Maybe could specify that if do not complete under a minute, then abort these jobs.

Benjamin-Loison commented 5 days ago

Both from htop CPU% and MEM% (biggest one being com.termux with 1.8) except significant values for NI and (-20) and VIRT (14.0G) I do not notice anything particular

Benjamin-Loison commented 5 days ago
time (timeout 3 sleep 5)
Output: ``` real 0m3.063s user 0m0.025s sys 0m0.045s ```

Source: the Stack Overflow answer 4581821

Benjamin-Loison commented 5 days ago
ps-check.sh: ```bash THRESHOLD=200 NB=$(ps aux | wc -l) if [ $NB -gt $THRESHOLD ] then termux-notification -t "ps aux is detected as reporting too many jobs ($NB compared to $THRESHOLD)" fi ```
crontab -l
...
* * * * * bens_folder/termux/ps-check.sh
Benjamin-Loison commented 5 days ago
Calendar reminder URL: ``` -----BEGIN PGP MESSAGE----- hF4DTQa9Wom5MBgSAQdAyWR1zOE37GCOSzUAmGD//QkW7YzFlyR/57Mvi0aEr3cw k3+RiF/ecwS4GKx3tZTzz+alyI+eiAgrIewa/s4sarrZx/Ky7m4bD/C6sVyzd54t 0qgBZxBnPGqULGoN+l1NeHP8DfEJ++xE2KuI54sp4eLA5J+FAsaN1ocPeuZKjm8f YAsogof3pL+3SUMmwmo1xA1vCzOYG6a0vHEt2oyG9ClGrNRS45/haRwTFmYFBGvN R3IEsge769bLrAZbU38kAORr12eqML1zWj1Gje9TKBdo78cgleaYQ/IV7e098vXg VOeDxOuhzWUsh3GsRTR/z0FU75nsXy59roc= =Jr7y -----END PGP MESSAGE----- ```
Benjamin-Loison commented 5 days ago

After reboot ps aux | wc -l returns 39.

Benjamin-Loison commented 5 days ago

So now let us wait.

Benjamin-Loison commented 5 days ago
timeout --help
Output: ``` Usage: timeout [OPTION] DURATION COMMAND [ARG]... or: timeout [OPTION] Start COMMAND, and kill it if still running after DURATION. Mandatory arguments to long options are mandatory for short options too. --preserve-status exit with the same status as COMMAND, even when the command times out --foreground when not running timeout directly from a shell prompt, allow COMMAND to read from the TTY and get TTY signals; in this mode, children of COMMAND will not be timed out -k, --kill-after=DURATION also send a KILL signal if COMMAND is still running this long after the initial signal was sent -s, --signal=SIGNAL specify the signal to be sent on timeout; SIGNAL may be a name like 'HUP' or a number; see 'kill -l' for a list of signals -v, --verbose diagnose to stderr any signal sent upon timeout --help display this help and exit --version output version information and exit DURATION is a floating point number with an optional suffix: 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days. A duration of 0 disables the associated timeout. Upon timeout, send the TERM signal to COMMAND, if no other SIGNAL specified. The TERM signal kills any process that does not block or catch that signal. It may be necessary to use the KILL signal, since this signal can't be caught. Exit status: 124 if COMMAND times out, and --preserve-status is not specified 125 if the timeout command itself fails 126 if COMMAND is found but cannot be invoked 127 if COMMAND cannot be found 137 if COMMAND (or timeout itself) is sent the KILL (9) signal (128+9) - the exit status of COMMAND otherwise GNU coreutils online help: Report any translation bugs to Full documentation or available locally via: info '(coreutils) timeout invocation' ```
Benjamin-Loison commented 5 days ago
* * * * * timeout 3 date >> dates.txt

works as wanted.