JavaScript is required to for searching.
跳过导航链接
退出打印视图
系统管理指南:Oracle Solaris Containers-资源管理和 Oracle Solaris Zones     Oracle Solaris 10 1/13 Information Library (简体中文)
search filter icon
search icon

文档信息

前言

第 1 部分资源管理

1.  Solaris 10 资源管理介绍

2.  项目和任务(概述)

3.  管理项目和任务

4.  扩展记帐(概述)

5.  管理扩展记帐(任务)

管理扩展记帐功能(任务列表)

使用扩展记帐功能

如何激活进程、任务和流的扩展记帐

如何使用启动脚本激活扩展记帐

如何显示扩展记帐状态

如何查看可用的记帐资源

如何取消激活进程记帐、任务记帐和流记帐

使用 libexacct 的 Perl 接口

如何递归打印 exacct 对象的内容

如何创建新的组记录并将其写入文件

如何打印 exacct 文件的内容

Sun::Solaris::Exacct::Object->dump() 的输出示例

6.  资源控制(概述)

7.  管理资源控制(任务)

8.  公平共享调度程序(概述)

9.  管理公平共享调度程序(任务)

10.  使用资源上限设置守护进程控制物理内存(概述)

11.  管理资源上限设置守护进程(任务)

12.  资源池(概述)

13.  创建和管理资源池(任务)

14.  资源管理配置示例

15.  Solaris Management Console 中的资源控制功能

第 2 部分区域

16.  Solaris Zones 介绍

17.  非全局区域配置(概述)

18.  规划和配置非全局区域(任务)

19.  关于安装、停止、克隆和卸载非全局区域(概述)

20.  安装、引导、停止、卸载和克隆非全局区域(任务)

21.  非全局区域登录(概述)

22.  登录到非全局区域(任务)

23.  移动和迁移非全局区域(任务)

24.  Oracle Solaris 10 9/10:将物理 Oracle Solaris 系统迁移到区域中(任务)

25.  关于安装了区域的 Oracle Solaris 系统上的软件包和修补程序(概述)

26.  在安装了区域的 Oracle Solaris 系统上添加和删除软件包和修补程序(任务)

27.  Oracle Solaris Zones 管理(概述)

28.  Oracle Solaris Zones 管理(任务)

29.  升级安装了非全局区域的 Oracle Solaris 10 系统

30.  各种 Oracle Solaris Zones 问题的故障排除

第 3 部分lx 标记区域

31.  关于标记区域和 Linux 标记区域

32.  规划 lx 标记区域配置(概述)

33.  配置 lx 标记区域(任务)

34.  关于安装、引导、停止、克隆和卸载 lx 标记区域(概述)

35.  安装、引导、停止、卸载和克隆 lx 标记区域(任务)

36.  登录到 lx 标记区域(任务)

37.  移动和迁移 lx 标记区域(任务)

38.  在 lx 标记区域中管理和运行应用程序(任务)

词汇表

索引

使用 libexacct 的 Perl 接口

如何递归打印 exacct 对象的内容

使用以下代码可以递归打印 exacct 对象的内容。请注意,此功能作为 Sun::Solaris::Exacct::Object::dump() 函数由库提供。此功能还可以通过 ea_dump_object() 公用函数提供。

sub dump_object
     {
             my ($obj, $indent) = @_;
             my $istr = '  ' x $indent;

             #
             # Retrieve the catalog tag.  Because we are 
             # doing this in an array context, the
             # catalog tag will be returned as a (type, catalog, id) 
             # triplet, where each member of the triplet will behave as 
             # an integer or a string, depending on context.
             # If instead this next line provided a scalar context, e.g.
             #    my $cat  = $obj->catalog()->value();
             # then $cat would be set to the integer value of the 
             # catalog tag.
             #
             my @cat = $obj->catalog()->value();

             #
             # If the object is a plain item
             #
             if ($obj->type() == &EO_ITEM) {
                     #
                     # Note: The '%s' formats provide s string context, so
                     # the components of the catalog tag will be displayed
                     # as the symbolic values. If we changed the '%s'
                     # formats to '%d', the numeric value of the components
                     # would be displayed.
                     #
                     printf("%sITEM\n%s  Catalog = %s|%s|%s\n", 
                        $istr, $istr, @cat);
                     $indent++;

                     #
                     # Retrieve the value of the item.  If the item contains
                     # in turn a nested exacct object (i.e., an item or
                     # group),then the value method will return a reference
                     # to the appropriate sort of perl object
                     # (Exacct::Object::Item or Exacct::Object::Group).
                     # We could of course figure out that the item contained
                     # a nested item orgroup by examining the catalog tag in
                     # @cat and looking for a type of EXT_EXACCT_OBJECT or
                     # EXT_GROUP.
                     #
                     my $val = $obj->value();
                     if (ref($val)) {
                             # If it is a nested object, recurse to dump it.
                             dump_object($val, $indent);
                     } else {
                             # Otherwise it is just a 'plain' value, so
                             # display it.
                             printf("%s  Value = %s\n", $istr, $val);
                     }

             #
             # Otherwise we know we are dealing with a group.  Groups
             # represent contents as a perl list or array (depending on
             # context), so we can process the contents of the group
             # with a 'foreach' loop, which provides a list context.
             # In a list context the value method returns the content
             # of the group as a perl list, which is the quickest
             # mechanism, but doesn't allow the group to be modified.
             # If we wanted to modify the contents of the group we could
             # do so like this:
             #    my $grp = $obj->value();   # Returns an array reference
             #    $grp->[0] = $newitem;
             # but accessing the group elements this way is much slower.
             #
             } else {
                     printf("%sGROUP\n%s  Catalog = %s|%s|%s\n",
                         $istr, $istr, @cat);
                     $indent++;
                     # 'foreach' provides a list context.
                     foreach my $val ($obj->value()) {
                             dump_object($val, $indent);
                     }
                     printf("%sENDGROUP\n", $istr);
             }
     }

如何创建新的组记录并将其写入文件

使用以下脚本可以创建新的组记录并将其写入名为 /tmp/exacct 的文件。

#!/usr/bin/perl

use strict;
use warnings;
use Sun::Solaris::Exacct qw(:EXACCT_ALL);
# Prototype list of catalog tags and values.
     my @items = (
             [ &EXT_STRING | &EXC_DEFAULT | &EXD_CREATOR      => "me"       ],
             [ &EXT_UINT32 | &EXC_DEFAULT | &EXD_PROC_PID     => $$         ],
             [ &EXT_UINT32 | &EXC_DEFAULT | &EXD_PROC_UID     => $<         ],
             [ &EXT_UINT32 | &EXC_DEFAULT | &EXD_PROC_GID     => $(         ],
             [ &EXT_STRING | &EXC_DEFAULT | &EXD_PROC_COMMAND => "/bin/rec" ],
     );

     # Create a new group catalog object.
     my $cat = ea_new_catalog(&EXT_GROUP | &EXC_DEFAULT | &EXD_NONE)

     # Create a new Group object and retrieve its data array.
     my $group = ea_new_group($cat);
     my $ary = $group->value();

     # Push the new Items onto the Group array.
     foreach my $v (@items) {
             push(@$ary, ea_new_item(ea_new_catalog($v->[0]), $v->[1]));
     }

     # Open the exacct file, write the record & close.
     my $f = ea_new_file('/tmp/exacct', &O_RDWR | &O_CREAT | &O_TRUNC)
        || die("create /tmp/exacct failed: ", ea_error_str(), "\n");
     $f->write($group);
     $f = undef;

如何打印 exacct 文件的内容

使用以下 Perl 脚本可以打印 exacct 文件的内容。

#!/usr/bin/perl

     use strict;
     use warnings;
     use Sun::Solaris::Exacct qw(:EXACCT_ALL);

     die("Usage is dumpexacct <exacct file>\n") unless (@ARGV == 1);

     # Open the exact file and display the header information.
     my $ef = ea_new_file($ARGV[0], &O_RDONLY) || die(error_str());
     printf("Creator:  %s\n", $ef->creator());
     printf("Hostname: %s\n\n", $ef->hostname());

     # Dump the file contents
     while (my $obj = $ef->get()) {
             ea_dump_object($obj);
     }

     # Report any errors
     if (ea_error() != EXR_OK && ea_error() != EXR_EOF)  {
             printf("\nERROR: %s\n", ea_error_str());
             exit(1);
     }
     exit(0);

Sun::Solaris::Exacct::Object->dump() 的输出示例

以下是对在如何创建新的组记录并将其写入文件中创建的文件运行 Sun::Solaris::Exacct::Object->dump() 时生成的输出示例。

Creator:  root
Hostname: localhost
GROUP
       Catalog = EXT_GROUP|EXC_DEFAULT|EXD_NONE
       ITEM
         Catalog = EXT_STRING|EXC_DEFAULT|EXD_CREATOR
         Value = me
       ITEM
         Catalog = EXT_UINT32|EXC_DEFAULT|EXD_PROC_PID
         Value = 845523
       ITEM
         Catalog = EXT_UINT32|EXC_DEFAULT|EXD_PROC_UID
         Value = 37845
       ITEM
         Catalog = EXT_UINT32|EXC_DEFAULT|EXD_PROC_GID
         Value = 10
       ITEM
         Catalog = EXT_STRING|EXC_DEFAULT|EXD_PROC_COMMAND
         Value = /bin/rec
ENDGROUP