歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> Unix資訊 >> 獲得 AIX系統中處理器資源的代碼示例

獲得 AIX系統中處理器資源的代碼示例

日期:2017/3/6 11:39:45   编辑:Unix資訊

本段的最後給出一段基於 Perl 的例子代碼,在 AIX系統5.3 和 6.1 上測試通過,可以偵測當前的AIX系統環境和 CPU 的類型和數量。這段代碼首先運行系統命令 oslevel 得到當前系統的版本,如果是 AIX6.1 則運行命令 lparstat 判斷當前系統是否為 WPAR。

無論 AIX 系統的版本如何,都加參數 -i 運行命令 lparstat 來獲得分區的個數,並以此判斷是否使用了微分區技術。最後調用命令 prtconf 輸出 CPU 的一些參數。

該段代碼可以幫助用戶快速了解當前環境,尤其適用於工作環境復雜或頻繁變更的場景。需要指出的是對於使用了微分區技術的系統,代碼的最後輸出的是虛擬處理器的數量。需要了解AIX系統中物理處理器和邏輯處理器狀態的用戶,可以參閱本文其他段落加以補充。

清單 4. 獲得當前的AIX系統環境和 CPU 的類型和數量的代碼示例

  1. # WPAR 僅存在於 AIX 6.1 系統
  2. my $oslevel = `oslevel`;
  3. if ($oslevel =~ m/6\.1/)
  4. {
  5. # 在 WPAR 中不帶參數運行 lparstat 命令只返回警告信息
  6. my $output = `lparstat`;
  7. if ($output =~ m/The output is applicable only to the Global Environment/)
  8. {
  9. print "This machine is one WPAR with following CPU assigned.\n";
  10. system ("prtconf | grep Processor");
  11. exit 0;
  12. }
  13. }
  14. # 使用– i 參數列出詳細的配置信息
  15. my @outputs = `lparstat -i`;
  16. foreach my $line (@outputs)
  17. {
  18. # 解析命令輸出並得到分區個數
  19. if ($line !~ m/Partition Number/) {next;}
  20. my ($blank, $partition_num) = split /Partition Number\s+:\s/, $line;
  21. chomp $partition_num;
  22. if ($partition_num eq '-') # full system 環境沒有劃分微分區
  23. {
  24. print "This machine is one full system without LPARs. The system has following
  25. physical CPUs installed.\n";
  26. }elsif ($partition_num > 1) # 如果存在多於一個的分區,該AIX系統使用了微分區技術
  27. {
  28. print "This machine is one LPAR with virtual following CPUs installed.
  29. To check the assignment of physical CPU, please log on HMC or AMM.\n";
  30. }else
  31. {
  32. print "Can not decide whether current environment is one LPAR or not.
  33. Please check HMC or AMM to decide this.\n";
  34. }
  35. }
  36. # 打印處理器本身的參數
  37. system ("prtconf | grep Processor");
  38. exit 0;

這樣,在AIX系統中獲得處理器資源的知識我們就講解完畢。

Copyright © Linux教程網 All Rights Reserved