I'm wondering if there are similar commands to getprop/setprop that 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 the
best Linux distribution (maybe the same thing on Mac) but is there something else?
I'll give an example of what I want to do: Let's say that I have a program that uses a default number of threads for parallelization and I want to change the number of threads after compilation. I can do so by adding an environment variable, setting it in my session then running my app.
The following code demonstrates this:
Code:
#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:
Code:
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 another way to do so without using the env variable, similar to Android?
I gauss that I can use the env approach on Mac too, but there is something else?
Thanks
