Файлы System/bin Android 12. Справочник.


  Все     Команда     Скрипт     Служба     Приложение  

rss_hwm_reset - исходный текст
#define LOG_TAG "rss_hwm_reset"
#include <dirent.h>
#include <string>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <log/log.h>
namespace {
// Resets RSS HWM counter for the selected process by writing 5 to
// /proc/PID/clear_refs.
void reset_rss_hwm(const char* pid) {
    std::string clear_refs_path =
            ::android::base::StringPrintf("/proc/%s/clear_refs", pid);
    ::android::base::WriteStringToFile("5", clear_refs_path);
}
}
// Clears RSS HWM counters for all currently running processes.
int main(int /* argc */, char** /* argv[] */) {
    DIR* dirp = opendir("/proc");
    if (dirp == nullptr) {
        ALOGE("unable to read /proc");
        return 1;
    }
    struct dirent* entry;
    while ((entry = readdir(dirp)) != nullptr) {
        // Skip entries that are not directories.
        if (entry->d_type != DT_DIR) continue;
        // Skip entries that do not contain only numbers.
        const char* pid = entry->d_name;
        while (*pid) {
            if (*pid < '0' || *pid > '9') break;
            pid++;
        }
        if (*pid != 0) continue;
        pid = entry->d_name;
        reset_rss_hwm(pid);
    }
    closedir(dirp);
    return 0;
}