run level

Paul Hite paul at prcrs.UUCP
Wed May 31 01:00:31 AEST 1989


In article <469 at anvil.oz>, michi at 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!



More information about the Comp.unix.wizards mailing list