michi@anvil.oz (Michael Henning) (05/26/89)
I've stumbled across a problem regarding run levels. Basically, I am writing a program which I want to run only in single user mode (it does fancy things with raw device files). The problem is, how can I reliably detect what the current run level is (I need to be able to do this from within a normal user program, with root privileges). One idea I had was to check whether /etc/utmp is empty. This seems to work on Xenix systems, but also seems clumsy. Is there some elegant and reliable way (i.e. portable) of asking init at what run level it is ? Any help with this would be great. Mail me if you like, and I will summarize. Michi. -- | The opinions expressed are my own, not those of my employer. | | | | Michael (Michi) Henning | | - We have three Michaels here, that's why they call me Michi |
paul@prcrs.UUCP (Paul Hite) (05/30/89)
In article <469@anvil.oz>, michi@anvil.oz (Michael Henning) writes: > Is there some elegant and reliable > way (i.e. portable) of asking init at what run level it is ? > With System V, the who command has several options added to it. One option reports the current run state. I'm not sure that I would call this "elegant", but it does seem to be the intended System V way to obtain the current run state. Here is a fragment of a shell script that uses this: #! /bin/sh set `who -r` if [ "$7" = "S" ] ; then echo We are in single user mode echo I will remount all disk drives umount -a mount -t hfs -a fi One warning about this. At least on a HP-UX system, I have seen this fail. If you get to single user mode via shutdown or init S, then the run state as reported by who -r is correct. But if you interrupt to boot-up sequence and go directly to single user mode, it will be wrong. Since some versions of TFM get this wrong, here is the output from a who -r: . system boot May 5 02:49 2 0 S ^ ^ ^ | | | previous run state | | | | number of times current run | | state has been entered | | current run state I hope that this helps. Paul Hite PRC Realty Systems McLean,Va uunet!prcrs!paul (703) 556-2243 DOS is a four letter word!