• python 判断当前执行用户是否是 root 用户


    非 root 用户下

    os-liming@os-W330-H30:~$ python
    Python 3.6.2 (default, Jul 17 2017, 13:39:29) 
    [GCC 6.4.0 20170704] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> print(os.getuid())
    1000
    >>> assert os.getuid() == 0, 'must use root'
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AssertionError: must use root

    root 下

    root@os-W330-H30:/# python
    Python 3.6.2 (default, Jul 17 2017, 13:39:29) 
    [GCC 6.4.0 20170704] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> assert os.getuid() == 0 , 'must use root'
    >>> print(os.getuid())
    0
  • 相关阅读:
    JSP第三章
    JSP第二章
    JSP第一章
    异常
    七种设计原则
    非泛型集合
    .NET第一章
    航班预定系统
    JSP数据交互(二)
    JSP数据交互(一)
  • 原文地址:https://www.cnblogs.com/tangda/p/15151509.html
Copyright © 2020-2023  润新知