michi@anvil.oz (Michael Henning) (06/08/89)
I while ago, I asked how to reliably and portably find out the run level of the machine from within a user program. I got quite a few replies, here is a brief summary. The key to it all is the /etc/utmp file. If everything works OK, there should be a run level entry in there (updated every time init changes state) which, of course, contains the current run level (see utmp.h for details). There are quite a few problems though... Depending on your flavour of operating system, the run level can be different things, e.g. 'M', 'm', 'S', 's', '1' can all indicate maintenance mode. On some systems, init does not reliably update the utmp file. One person sent me mail saying that under HP/UX, depending on how the machine is put into maintenance mode, init does or does not update utmp. Under 386 Xenix, V2.3, when the machine comes up in multi-user mode, there is neither a boot time nor a run level entry in utmp, and in maintenance mode, the utmp file is empty. Overall, it looks like there is no really portable way of doing this, different flavours of UNIX require different code... -- | 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 |