Does the code block? If it doesn't, there should be no ramifications of running it in the main thread. You can, however, do that from another thread, with:
Context.runOnUiThread(new Runnable() {
getPathOfExecutable();
});
This is the cleanest work around I can think of, short of editing the permissions of your file (that you can't get the path of without running your code on the main thread anyways) because you have r/w privileges on /proc/self/exe.
This is very weird, and I am still researching the permission differences in different threads on android.
If you can get it working in the main thread, my opinion would be to just do it in the main thread, and not worry much about optimization, as the performance is no different on different threads.
What would be a workaround to get the path of the current executable?
Since every Android app is forked from Zygote, which is the first Java vm process when the virtual machine created by /system/bin/app_process at system booting.
If you try to read the /proc/self/exe from your Android app, the actual executable will be /system/bin/app_process. Even if you read this outside of your app's main thread, the result is the same and it wouldn't have the permission error in theory.
The question you asked is a kind of weird problem, I have tested with the following code on Android 2.3.3 and worked fine.
new Thread() {
/* (non-Javadoc)
* @see java.lang.Thread#run()
*/
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
try {
Log.d(TAG, new File("/proc/self/exe").getCanonicalFile().getPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
I want to install clipgrab from clipgrab.org. I download the AppImage file, make sure I click "Allow executing file as program" checkbox in the properties for the file, I double click it and I get this message:
Cannot mount AppImage, please check your FUSE setup
So I uninstall and reinstall FUSE:
sudo apt-get purge fuse
sudo apt-get install fuse
I try again and I get the same message. What do I do? I'm honestly stuck. I can install clipgrab with:
sudo apt-get install clipgrab
but that doesn't give me the latest version. I haven't been able to update it also even though I added the ppa from launchpad. This is just eternally frustrating. Every guide I tried leads nowhere. I just want the latest version of clipgrab and a method to update it when a new version comes out. Thanks for anyone who could help.
I am seeing this too when i try and check out file descriptors for my own users process. From what I can tell, it is a cheap work around for a security hole in the /proc file system that allows you to open up files via /proc/$pid/fd bypassing the permissions. It seems they just made all file descriptors in proc owned by root.
I can do this fine on ubuntu, but not CentOS.
You can read about it here: http://lwn.net/Articles/359286/
As @JellicleCat said in comments, if you're in a Docker container (like me) just go to host's terminal. The container processes belongs to it.