There is a persistent process which I desire to persistently kill.
To do so, I made a very simple python script:
import os
import signal
While True:
os.system("ps >> /sdcard/newdata.txt")
file = open("/sdcard/newdata.txt","r")
for x in file:
if (len(x.split())<9):
continue
elif (x.split()[8] == "/system/bin/XXXX"):
pid = int(x.split()[1])
os.kill(pid, signal.SIGKILL)
break
file.close()
the XXXX represents the name of the binary of the file which triggers the process.
In my specific case this binary, XXXX, is a good way of recognizing the process I want to kill.
I think it should work, but instead it returns an error:
"ProcessLookupError: [Errno 3] No such process"
I printed the pid and ran the script multiple times.
The pid is fixed which should mean the process didn't respawn, still it always returns an error as if the pid is wrong.
Can anyone explain this?
Related
I'm trying to run valgrind on an android OS but it couldn't start and it shows this errors that i couldn't find how to solve:
valgrind: Startup or configuration error:
Can't create client cmdline file in /tmp/valgrind_proc_87_cmdline_876a7612
valgrind: Unable to start up properly. Giving up.
Thanks in advance !
I tried to change the default path that valgrind use and which is shown on the error log but i couldn't make it
The problem is happening in the code where the Valgrind host is creating a fake /proc/<pid>/cmdline.
This file should be created in the location given by the first valid item in the following list:
The TMPDIR environment variable
The constant VG_TMPDIR that gets baked into the binary via a configure time option. This defaults to /tmp but can be overriden using configure --with-tmpdir=/your/tmp/dir. That would require that you get the Valgrind source and configure and build it. It is possible that you are using a package that was built using this option and is not compatible with your system.
Last resort, "/tmp"
All of the above checks just test that the string is non-null and not empty. They do not test for the existance and accessibility of the directory. That gets determined by the Valgrind version of mkstemp and the error message comes from 'valgrind_main'.
Valgrind needs to create a file TMPDIR/valgrind_proc_PID_cmdline_RAND where TMPDIR is described above, PID is the pid of the Valgrind process and RAND is a random number.
There is at least one other similar files that get created, for auxv.
There are no Valgrind command line options to turn off the creation of these files.
I am retrieving Logcat of Android device from command line by using adb logcat command. I have no idea of Android device logs encoding (actually trying to find this information for last 3 months) - as there can be many languages in device logs e.g Chinese, Japanese, Arabic or special characters like Emoji or © and more.
My Python3 script looks as follows:
import subprocess
ADB_LOCATION = "/Users/F1sherKK/Library/Android/sdk/platform-tools/adb"
ADB_DEVCE = "-s emulator-5554"
ADB_LOGCAT = "logcat"
LOGCAT_MONITOR_CMD = "{} {} {}".format(ADB_LOCATION, ADB_DEVCE, ADB_LOGCAT)
with subprocess.Popen(LOGCAT_MONITOR_CMD, shell=True,
stdout=subprocess.PIPE, bufsize=1,
universal_newlines=True, encoding='utf-8') as p:
for line in p.stdout:
line_cleaned = line.strip()
# do something with Logcat line
But at some point this line crashes:
for line in p.stdout:
With following error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position
89: invalid start byte
I am not sure anymore where is the error. I think that I am using wrong encoding as I don't know encoding of Android Logcat. Tried various common encodings like UTF-32, UTF-16 or ASCII but it always crashes.
How to fix this or at least make partially work - e.g. make it ignore characters it cannot decode?
Better late than never:
The "problem" is that you have non-decodable bytes in the logcat output. There's nothing wrong from the Python perspective, it's just invalid data.
As far as I can tell, adb logcat output should never be non-decodable bytes. If you're seeing bytes that can't be decoded by UTF-8, then your logcat data is probably just corrupt and your best bet is to clear it and try again:
$ adb logcat -c
I am writing a small Android program that can check how many files contains a certain string without reading completely their contents
Therefore, I've found a good way to do it is using grep -q command. Because of executing the command doesn't output but a exit code (0 : match, 1 : not match)
However I have no idea that how to get the exit code after executing the command completed by C language in JNI.
I am trying to start a native app from within an android app (Android Jelly bean (4.1.2)). I am able to start the native app manually from adb, however it does not start from android. The native app is inside AsyncTask and it is started by the doInBackground function. The command I use to start the app inside android is:
process = Runtime.getRuntime().exec("/data/data/MyAppDir/CAL_Android > /data/data/MyAppDir/out.txt 2>&1 &");
I simplified the command as below, but still did not start:
process = Runtime.getRuntime().exec("/data/data/MyAppDir/CAL_Android");
My various attempts at debugging the issue:
Start a simple command, like "touch file.txt" from android. Works
Moved the native app to /data/local/tmp. Did not work.
Changed the execute permission to 777 (rwxrwxrwx). Did not work.
Changed the owner to root apart from that of the app. Did not work.
Tried using a thread (implements Runnable instead of extends AsyncTask). Did not work.
Execute command using "su -c" ("su -c /data/data/MyAppDir/CAL_Android"). Did not work.
Place the command to execute inside a shell script and invoke shell script from Android. Did not work.
I checked the dmesg output and the error I get is:
<7>[14156.022980] CAL_Android: unhandled page fault (11) at 0x0000000c, code 0x017
<1>[14156.023010] pgd = e6204000
<1>[14156.026306] [0000000c] *pgd=b0728831, *pte=00000000, *ppte=00000000
<4>[14156.032777]
<4>[14156.034242] Pid: 9408, comm: CAL_Android
<4>[14156.051821] CPU: 0 Tainted: G W (3.4.0-ge11b2fc-dirty #1)
<4>[14156.061557] PC is at 0x4012aa22
Can someone please tell me what the problem is?
EDIT:
The dmesg output is not correct. After checking a few more times, I am not getting the error message in dmesg. The crash seems to have happened due to a different unknown reason. But I have added an answer to the reason for not being able to start the native app from android. Hopefully this helps someone who faces a similar issue.
I found out why the android app was not able to start the native app, by using the below 2 lines and printing them in the log.
BufferedReader std_input = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader std_error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while ((line = std_error.readLine()) != null) {
Log.i(TAG, line);
}
When I used "su -c" before my command, I got this error message:
su: uid <xyz> not allowed to su
and when I did not use "su -c" I got this one instead:
"Cannot open socket: Operation not permitted"
The reason is that, the android app does not have root permission to start the native app and the native app needs root permission to open a socket for sending and receiving data.
Sometimes I see the following logcat output such as that below:
<3>[ 283.152845] init: untracked pid 4217 exited
<3>[ 283.162185] init: untracked pid 4078 exited
<3>[ 283.173691] init: untracked pid 1504 exited
<3>[ 283.177018] init: untracked pid 1468 exited
What is the meaning of the log of init: untracked pid xxxx exited?
use logcat and read the huge log carefully. You might find the program that crashes all the time.
There may be many different reasons, one of them is that android init trying to
initialize services specified by init.rc failed.
You can try to bisect the services started from init.rc first, and once you find
the errornous service, then try to fix the specific service start up errors, which
may be the kernel driver error, or android hal driver error, library fault, or
sometimes android framework error.
Technically, this message (modern version of which is "Untracked pid XXX exited with status YY") means that Android init sees a child process exit (that is, receives SIGCHLD signal and then gets its pid with waitpid()), but it can't associate that process with any of configured services (see this question on Android init service configuration).
This in turn opens up a question of what can daemonize itself in Android environment and how to find it. But I don't think that I can answer that, the only suggestion that I have is getting root access and checking processes.