multi/single-user mode flag?

Brandon S. Allbery allbery at ncoast.UUCP
Sun May 22 02:35:46 AEST 1988


As quoted from <3595 at psuvax1.psu.edu> by okunewck at gondor.cs.psu.edu (Phil OKunewick):
+---------------
| 	Is there any nice way for a program to tell whether a generic
| unix system is in single-user or multi-user mode?  Two ideas here are
| to read init's memory (not standard under different unixes) or to check
| what processes are running (kludge).
+---------------

who > /tmp/who$$
if test -s /tmp/who$$; then
	echo multiuser
else
	echo singleuser
fi
rm /tmp/who$$

Who doesn't produce output in singleuser mode, since it's getty that writes
the login records and init spawns a shell directly in singleuser mode.  This
is true under all OSes I've checked (System III/V, Xenix 2/3/5, V7).  It is
most likely true of BSD (2.x and 4.x) as well.

The gotcha:  utmp formats are anything but compatible between V7/BSD and
System V/Xenix 5.  The easiest portable way is to have a shell script to do
the dump, and have it do the "who" stuff above.
-- 
	      Brandon S. Allbery, moderator of comp.sources.misc
	{well!hoptoad,uunet!marque,cbosgd,sun!mandrill}!ncoast!allbery
Delphi: ALLBERY						     MCI Mail: BALLBERY



More information about the Comp.unix.wizards mailing list