[comp.unix.questions] Current Run-Level: How can you tell?

sralston@srwic.UUCP (Steve Ralston) (04/23/91)

Sorry as I'm sure this is a FAQ or RTFM question, but, I've looked quite
a few places and can't find a way to tell what the current run level of
a Unix system is (i.e. "init" level).

I am most interested in a solution that is portable, can be performed inside
a C program, or ANY OTHER method you can come up with; in about that order
of precedence.

As always, thanks in advance!
-- 
Steve Ralston    (sralston@srwic.UUCP || ..!uunet!ncrlnk!ncrwic!srwic!sralston)
235 N Zelta, Wichita, KS 67206

dag@fciva.FRANKCAP.COM (Daniel A. Graifer) (04/24/91)

In article <1991Apr23.024433.10460@srwic.UUCP> sralston@srwic.UUCP (Steve Ralston) writes:
>Sorry as I'm sure this is a FAQ or RTFM question, but, I've looked quite
>a few places and can't find a way to tell what the current run level of
>a Unix system is (i.e. "init" level).

It may depend on your version of unix, but in my port of SysV 3.1.2
"who -r" reports various things about init including the current run
level.  Many of the vendor supplied rc2.d init files use this to make
sure certain things do/don't happen during transition from one state
to another.

I don't know how you would do it from 'c'.

Dan
-- 
Daniel A. Graifer			Coastal Capital Funding Corp.
Sr. Vice President, Financial Systems	7900 Westpark Dr. Suite A-130
(703)821-3244				McLean, VA  22102
uunet!fciva!dag				fciva.FRANKCAP.COM!dag@uunet.uu.net

ege@cbnews.cb.att.com (Ernie Englehart) (04/24/91)

In article <1991Apr23.024433.10460@srwic.UUCP> sralston@srwic.UUCP (Steve Ralston) writes:
=Sorry as I'm sure this is a FAQ or RTFM question, but, I've looked quite
=a few places and can't find a way to tell what the current run level of
=a Unix system is (i.e. "init" level).
=
=I am most interested in a solution that is portable, can be performed inside
=a C program, or ANY OTHER method you can come up with; in about that order
=of precedence.

The command "who -r" does the trick.

>As always, thanks in advance!

You're welcome.
-- 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|   Ernie Englehart   AT&T Network Systems   Columbus, Ohio   |
|   att!cbnmva!ege                                            |
|                     GO OHIO STATE BUCKEYES!!!               |

peter@ficc.ferranti.com (Peter da Silva) (04/25/91)

In article <1991Apr23.024433.10460@srwic.UUCP> sralston@srwic.UUCP (Steve Ralston) writes:
> Sorry as I'm sure this is a FAQ or RTFM question, but, I've looked quite
> a few places and can't find a way to tell what the current run level of
> a Unix system is (i.e. "init" level).

Assuming you're using System V (which is the only place I know of run
levels in anyway)...

	% who -r
	   .       run-level 3  Apr 22 08:26    3    0    S
	%

Bobs-your-uncle!

In C, you could easily grovel through /etc/utmp if you don't want to
fork a popen.
-- 
Peter da Silva.  `-_-'  peter@ferranti.com
+1 713 274 5180.  'U`  "Have you hugged your wolf today?"

schwartz@groucho.cs.psu.edu (Scott Schwartz) (04/25/91)

Ernie Englehart writes:
| The command "who -r" does the trick.

Bizarre.  Why stick that in the "who" command?  I guess "cat" and "ls"
have too many options and "who" needed some... :-)

prl@iis.ethz.ch (Peter Lamb) (04/25/91)

Ernie Englehart writes:
| The command "who -r" does the trick.

Not on SunOS or Ultrix.


--
Peter Lamb
uucp:  uunet!mcsun!ethz!prl	eunet: prl@iis.ethz.ch	Tel:   +411 256 5241
Integrated Systems Laboratory
ETH-Zentrum, 8092 Zurich

cpcahil@virtech.uucp (Conor P. Cahill) (04/25/91)

schwartz@groucho.cs.psu.edu (Scott Schwartz) writes:
>Ernie Englehart writes:
>| The command "who -r" does the trick.

>Bizarre.  Why stick that in the "who" command?  I guess "cat" and "ls"
>have too many options and "who" needed some... :-)

I know this doesn't make much sense from the user's viewpoint, but from
the programmers viewpoint it may:

	The reson is that the information is in the /etc/utmp file and who
	is one of the few programs that processes this file.

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

subbarao@phoenix.Princeton.EDU (Kartik Subbarao) (04/25/91)

In article <prl.672572026@iis> prl@iis.ethz.ch (Peter Lamb) writes:
>Ernie Englehart writes:
>| The command "who -r" does the trick.
>
>Not on SunOS or Ultrix.

SunOS and Ultrix don't know the meaning of the word "run level", so there's
no need.

		-Kartik
--
internet# rm `df | tail +2 | awk '{ printf "%s/quotas\n",$6}'`

subbarao@phoenix.Princeton.EDU -| Internet
kartik@silvertone.Princeton.EDU (NeXT mail)  
SUBBARAO@PUCC.BITNET			          - Bitnet

slootman@dri.nl (Paul Slootman) (04/25/91)

In article <z.8Goc1y1@cs.psu.edu> schwartz@groucho.cs.psu.edu (Scott Schwartz) writes:
>
>Ernie Englehart writes:
>| The command "who -r" does the trick.
>
>Bizarre.  Why stick that in the "who" command?  I guess "cat" and "ls"
>have too many options and "who" needed some... :-)

who (at least on the System V machine I know) reads /etc/utmp (or some
similar file if you specify it). Amongst other things, the run level
is stored in /etc/utmp.
With "who -a" you get every entry in the utmp file....

Paul.
-- 
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
: slootman@dri.nl           : You are wise, witty and wonderful, but you      :
: ...!hp4nl!dri500!slootman : spend too much time reading this sort of trash. :
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

peter@ficc.ferranti.com (Peter da Silva) (04/25/91)

In article <z.8Goc1y1@cs.psu.edu> schwartz@groucho.cs.psu.edu (Scott Schwartz) writes:
> Bizarre.  Why stick that in the "who" command?

Because "who" grovels through /etc/utmp, and that's where the current run
level is stored.
-- 
Peter da Silva.  `-_-'  peter@ferranti.com
+1 713 274 5180.  'U`  "Have you hugged your wolf today?"

ghe@physics.orst.edu (Guangliang He) (04/25/91)

In article <z.8Goc1y1@cs.psu.edu>, schwartz@groucho.cs.psu.edu (Scott Schwartz) writes:
|> 
|> Ernie Englehart writes:
|> | The command "who -r" does the trick.
|> 
|> Bizarre.  Why stick that in the "who" command?  I guess "cat" and "ls"
|> have too many options and "who" needed some... :-)

I think the reason is `who' opens the utmp file and the run level 
infomation is stored in utmp (at least on the sys V).

---
  Guangliang He
  ghe@physics.orst.edu

rcd@ico.isc.com (Dick Dunn) (04/26/91)

dag@fciva.FRANKCAP.COM (Daniel A. Graifer) writes:

> It may depend on your version of unix, but in my port of SysV 3.1.2
> "who -r" reports various things about init including the current run
> level...

This is a dependable SysVism.

> I don't know how you would do it from 'c'.

See utmp.h.  If the ut_type field is RUN_LVL, the string "run-level n"
where n is the current run level, is in the ut_line field.
-- 
Dick Dunn     rcd@ico.isc.com -or- ico!rcd       Boulder, CO   (303)449-2870
   ...While you were reading this, Motif grew by another kilobyte.

wes@harem.clydeunix.com (Wes Peters) (05/02/91)

In article <599@fciva.FRANKCAP.COM>, dag@fciva.FRANKCAP.COM (Daniel A. Graifer) writes:
> It may depend on your version of unix, but in my port of SysV 3.1.2
> "who -r" reports various things about init including the current run
> level.  Many of the vendor supplied rc2.d init files use this to make
> sure certain things do/don't happen during transition from one state
> to another.
> 
> I don't know how you would do it from 'c'.

Use getutent(3) on {/etc,/usr/adm}/wtmp to find the LAST run-level
entry.  Sorry, I don't have any System V man pages with me, or I'd try
to hack up a simple loop for you.  Getutent(3) and utmp(5) should have
enough info to get you started.

	Wes Peters
-- 
#include <std/disclaimer.h>                               The worst day sailing
My opinions, your screen.                                   is much better than
Raxco had nothing to do with this!                        the best day at work.
     Wes Peters:  wes@harem.clydeunix.com   ...!sun!unislc!harem!wes