Detect Linux Runlevel

Lew Pitcher lew.pitcher at digitalfreehold.ca
Mon Dec 5 16:38:00 EST 2016


On Monday December 5 2016 16:25, in comp.lang.python, "DFS" <nospam at dfs.com>
wrote:

> On 12/05/2016 03:58 PM, Wildman wrote:
>> I there a way to detect what the Linux runlevel is from
>> within a Python program?  I would like to be able to do
>> it without the use of an external program such as 'who'
>> or 'runlevel'.
> 
> 
> Why not?
> 
> '>>> import os
> '>>> os.system("systemctl get-default")
> graphical.target

Because

  $ cat rlevel.py
  import os
  os.system("systemctl get-default")
  16:36 $ python rlevel.py
  sh: systemctl: command not found
  16:36 $ 


> systemd 'graphical.target' corresponds to the old runlevel 5.

Yes? So?

The OP asked for the runlevel, not the systemd target.


-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request




More information about the Python-list mailing list