Unix Technical Forum

Detecting run levels

This is a discussion on Detecting run levels within the HP-UX Operating System forums, part of the Unix Operating Systems category; --> Is there some way to detect run levels programmatically? I see no library functions or system calls that return ...


Go Back   Unix Technical Forum > Unix Operating Systems > HP-UX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-16-2008, 07:01 PM
Dan Koren
 
Posts: n/a
Default Detecting run levels



Is there some way to detect run
levels programmatically? I see
no library functions or system
calls that return information
about the current system run
level. Have I missed something?

Thx,



dk


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-16-2008, 07:01 PM
barts@smaalders.net
 
Posts: n/a
Default Re: Detecting run levels

What are you trying to do?

Run levels are a pretty nebulous thing in general;
SMF in Solaris 10 talks about services and dependancies....

- Bart

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-16-2008, 07:01 PM
Logan Shaw
 
Posts: n/a
Default Re: Detecting run levels

Dan Koren wrote:
> Is there some way to detect run
> levels programmatically? I see
> no library functions or system
> calls that return information
> about the current system run
> level. Have I missed something?


Run "who -r". Its output will tell you the run level.

If you need to do this from some compiled language,
you can use popen() and then parse the output yourself.

From the shell, it's pretty easy: just do something like this:

runlevel ()
{
set `who -r`
echo "$3"
}

Then you can do

echo "The runlevel is `runlevel`."

Also, if you do "truss who -r", it seems to read /var/adm/utmpx
and read /etc/inittab. So, you might be able to do something
involving reading /var/adm/utmpx by calling getutxent(). However,
it seems safer to just read the output of "who -r" to me...

- Logan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-16-2008, 07:01 PM
Dan Koren
 
Posts: n/a
Default Re: Detecting run levels


OK, thanks.


dk


"Logan Shaw" <lshaw-usenet@austin.rr.com> wrote in message
news:KVP0e.29568$Ux.3522@tornado.texas.rr.com...
> Dan Koren wrote:
>> Is there some way to detect run
>> levels programmatically? I see
>> no library functions or system
>> calls that return information
>> about the current system run
>> level. Have I missed something?

>
> Run "who -r". Its output will tell you the run level.
>
> If you need to do this from some compiled language,
> you can use popen() and then parse the output yourself.
>
> From the shell, it's pretty easy: just do something like this:
>
> runlevel ()
> {
> set `who -r`
> echo "$3"
> }
>
> Then you can do
>
> echo "The runlevel is `runlevel`."
>
> Also, if you do "truss who -r", it seems to read /var/adm/utmpx
> and read /etc/inittab. So, you might be able to do something
> involving reading /var/adm/utmpx by calling getutxent(). However,
> it seems safer to just read the output of "who -r" to me...
>
> - Logan



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-16-2008, 07:01 PM
Dan Koren
 
Posts: n/a
Default Re: Detecting run levels

<barts@smaalders.net> wrote in message
news:1111736443.771703.165190@l41g2000cwc.googlegr oups.com...
>
> What are you trying to do?



Somewhat devious things as usual.

>
> Run levels are a pretty nebulous thing in general;



Got that...



dk


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-16-2008, 07:01 PM
UNIX admin
 
Posts: n/a
Default Re: Detecting run levels

> Is there some way to detect run
> levels programmatically? I see
> no library functions or system
> calls that return information
> about the current system run
> level. Have I missed something?


How about `who -r`?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-16-2008, 07:02 PM
Florian Anwander
 
Posts: n/a
Default Re: Detecting run levels

Hi Dan

> Is there some way to detect run
> levels programmatically? I see
> no library functions or system
> calls that return information
> about the current system run
> level. Have I missed something?

As Logan Shaw described,
man 4 utmp
and
man 3c getut
should be good starting points.

Pay attention: This tells you in which runlevel the system should(!) to
be. Not whether all rc-scripts and inittab-stuff worked fine (which is
the finally essential thing!).

Florian

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com