欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

netdata:检查当前是否是root权限运行

程序员文章站 2022-05-10 09:39:57
...

检查当前是否是root权限运行

static int am_i_running_as_root() {
    uid_t uid = getuid(), euid = geteuid();

    if(uid == 0 || euid == 0) {
        printf("I am running with escalated privileges, uid = %u, euid = %u.\n", uid, euid);
        return 1;
    }

    printf("I am not running with escalated privileges, uid = %u, euid = %u.\n", uid, euid);
    return 0;
}
相关标签: # C++