Check if user is root in C?

后端 未结 3 1480
臣服心动
臣服心动 2021-01-30 20:41

How can I verify if the user is root?

3条回答
  •  粉色の甜心
    2021-01-30 21:20

    getuid or geteuid, depending on what you really mean. In either case, 0 means root.

    if(geteuid() != 0)
    {
      // Tell user to run app as root, then exit.
    }
    

    The point made by R is valid. You should consider trial and error, or another approach that does not explicitly require root.

提交回复
热议问题