简体   繁体   English

在Python脚本中查找当前的Linux运行级别

[英]Find out current linux runlevel in Python script

I was wondering what is the best way (if there's any) of knowing what run-level I (well... my Python script) is in. (You know... 0--> Halting, 1--> Single user, 2345--> Kind of regular run, 6 --> Rebooting) 我想知道了解(我的Python脚本) 运行级别的最佳方法(如果有的话)。(您知道... 0->暂停,1->单用户,2345->常规运行的种类,6->重新启动)

I've been taking a look to the os, sys and subprocess libraries, but none of them seem to have anything that returns the run-level of execution. 我一直在研究os, syssubprocess库,但是它们似乎都没有返回运行级别的东西。

I know I can execute the system's runlevel command, but I would be surprised if Python didn't have something more... "native" for it. 我知道我可以执行系统的runlevel命令,但是如果Python没有更多功能……“本机”,我会感到惊讶。

Thank you in advance 先感谢您

I guess you are stuck using the 'runlevel' command, nothing native for Python. 我猜您一直在使用“运行级别”命令,Python本身没有。 The result would be useless anyway, because it dependents on the distribution. 无论如何,结果将是无用的,因为它取决于分布。 Some distributions implement an other meaning to the same number. 一些发行版对相同的数字实现了其他含义。 So no standardization in this area. 因此,这方面没有标准化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM