I'm wondering if there is similar commands to getprop/setprop
that are exist in Android.
I want to enable to do changes for certain properties for a compiled app without compiling it again.
I know that on Android I can do so with adb shell setprop
but I didn't find something similar in Linux/Mac.
There is a way to do something like that with environment variable on Linux (maybe the same thing on Mac) but is there something else?
I'll give an example for what I want to do: Let's say that I have a program that uses a default number of threads for parallelization and I wont to change the number of threads after compilation. I can do so by adding an environment variable, set it in my session then run my app.
The following code demonstrates this:
#include <sstream>
#include <cstdlib>
template <class T>
bool getEnv(const char* envVariable, T& value) {
auto envValue = getenv(envVariable);
if (!envValue) {
return false;
}
if constexpr (std::is_same_v<T, int>) {
auto tempValue = strtol(envValue, nullptr, 10);
if (tempValue < std::numeric_limits<int>::min() ||
tempValue > std::numeric_limits<int>::max()) {
return false;
}
value = tempValue;
} else if constexpr (std::is_same_v<T, double>) {
auto tempValue = strtod(envValue, nullptr);
if (tempValue < std::numeric_limits<double>::min() ||
tempValue > std::numeric_limits<double>::max()) {
return false;
}
value = static_cast<double>(tempValue);
} else {
// make sure this won't compile
static_assert(!std::is_same_v<T, T>);
}
return true;
}
int main() {
int number_of_threads;
int status = getEnv("NUMBER_OF_THREADS", number_of_threads);
if (!status) {
std::cerr << "Failed to get NUMBER_OF_THREADS\n";
return 1;
}
std::cout << "NUMBER_OF_THREADS=" << number_of_threads << "\n";
return 0;
}
On the terminal:
idancw:~/envTest/cmake-build-debug> export NUMBER_OF_THREADS=4
idancw:~/envTest/cmake-build-debug> ./test
NUMBER_OF_THREADS=4
idancw:~/envTest/cmake-build-debug> export NUMBER_OF_THREADS=10
idancw:~/envTest/cmake-build-debug> ./test
NUMBER_OF_THREADS=10
Is there other way to do so without using env variable, similar to Android?
I gauss that I can use the env approach on Mac too, but there is something else?
Thanks :)