獲得 AIX系統(tǒng)中處理器資源的代碼示例
本段的***給出一段基于 Perl 的例子代碼,在 AIX系統(tǒng)5.3 和 6.1 上測試通過,可以偵測當(dāng)前的AIX系統(tǒng)環(huán)境和 CPU 的類型和數(shù)量。這段代碼首先運(yùn)行系統(tǒng)命令 oslevel 得到當(dāng)前系統(tǒng)的版本,如果是 AIX6.1 則運(yùn)行命令 lparstat 判斷當(dāng)前系統(tǒng)是否為 WPAR。
無論 AIX 系統(tǒng)的版本如何,都加參數(shù) -i 運(yùn)行命令 lparstat 來獲得分區(qū)的個(gè)數(shù),并以此判斷是否使用了微分區(qū)技術(shù)。***調(diào)用命令 prtconf 輸出 CPU 的一些參數(shù)。
該段代碼可以幫助用戶快速了解當(dāng)前環(huán)境,尤其適用于工作環(huán)境復(fù)雜或頻繁變更的場景。需要指出的是對(duì)于使用了微分區(qū)技術(shù)的系統(tǒng),代碼的***輸出的是虛擬處理器的數(shù)量。需要了解AIX系統(tǒng)中物理處理器和邏輯處理器狀態(tài)的用戶,可以參閱本文其他段落加以補(bǔ)充。
清單 4. 獲得當(dāng)前的AIX系統(tǒng)環(huán)境和 CPU 的類型和數(shù)量的代碼示例
- # WPAR 僅存在于 AIX 6.1 系統(tǒng)
- my $oslevel = `oslevel`;
- if ($oslevel =~ m/6\.1/)
- {
- # 在 WPAR 中不帶參數(shù)運(yùn)行 lparstat 命令只返回警告信息
- my $output = `lparstat`;
- if ($output =~ m/The output is applicable only to the Global Environment/)
- {
- print "This machine is one WPAR with following CPU assigned.\n";
- system ("prtconf | grep Processor");
- exit 0;
- }
- }
- # 使用– i 參數(shù)列出詳細(xì)的配置信息
- my @outputs = `lparstat -i`;
- foreach my $line (@outputs)
- {
- # 解析命令輸出并得到分區(qū)個(gè)數(shù)
- if ($line !~ m/Partition Number/) {next;}
- my ($blank, $partition_num) = split /Partition Number\s+:\s/, $line;
- chomp $partition_num;
- if ($partition_num eq '-') # full system 環(huán)境沒有劃分微分區(qū)
- {
- print "This machine is one full system without LPARs. The system has following
- physical CPUs installed.\n";
- }elsif ($partition_num > 1) # 如果存在多于一個(gè)的分區(qū),該AIX系統(tǒng)使用了微分區(qū)技術(shù)
- {
- print "This machine is one LPAR with virtual following CPUs installed.
- To check the assignment of physical CPU, please log on HMC or AMM.\n";
- }else
- {
- print "Can not decide whether current environment is one LPAR or not.
- Please check HMC or AMM to decide this.\n";
- }
- }
- # 打印處理器本身的參數(shù)
- system ("prtconf | grep Processor");
- exit 0;
這樣,在AIX系統(tǒng)中獲得處理器資源的知識(shí)我們就講解完畢。
【編輯推薦】