Cover V10, I10

Article
Listing 1
Listing 2
Listing 3

oct2001.tar

Listing 2 Sample implementation for the uptime utility (Perl)

 1  #!/opt/esp/common/bin/perl
 2
 3  use POSIX;
 4  use Solaris::Kstat;
 5   
 6  $hz = sysconf(_SC_CLK_TCK);
 7  $pk = new Solaris::Kstat;
 8   
 9  $clk_intr      = $pk->{unix}->{0}->{system_misc}->{clk_intr};
10  $avenrun_1min  =
11     ( $pk->{unix}->{0}->{system_misc}->{avenrun_1min}*1.0 / (1<<8) );
12  $avenrun_5min  =
13     ( $pk->{unix}->{0}->{system_misc}->{avenrun_5min}*1.0 / (1<<8) );
14  $avenrun_15min =
15     ( $pk->{unix}->{0}->{system_misc}->{avenrun_15min}*1.0 / (1<<8) );
16
17  $dd = int( $clk_intr / ( $hz * 86400 ) );
18  $clk_intr -= $dd * $hz * 86400;
19  $hh = int( $clk_intr / ( $hz * 3600 ) );
20  $clk_intr -= $hh * $hz * 3600;
21  $mm = int( $clk_intr / ( $hz * 60 ) );
22  $clk_intr -= $mm * $hz * 60;
23  $ss = int( $clk_intr / $hz );
24
25  printf( "Up: %d day(s) %d hour(s) %d minute(s) %d second(s), ",
26     $dd, $hh, $mm, $ss );
27  printf( "load average: %.2f, %.2f, %.2f\n",
28     $avenrun_1min, $avenrun_5min, $avenrun_15min );